Hi, Is it possible, when using a find method with a Model, to record the MySQL thread ID for the subsequent database query? Does ActiveRecord expose this? Many thanks, Michaël -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Aug-03 12:24 UTC
Re: ActiveRecord - find MySQL connection/thread ID for query
Michaël wrote:> Hi, > > Is it possible, when using a find method with a Model, to record the > MySQL thread ID for the subsequent database query? Does ActiveRecord > expose this?Why on earth would you need this? What are you trying to achieve?> > Many thanks, > Micha�lBest, -- Marnen Laibow-Koser marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Michaël
2010-Aug-03 13:08 UTC
Re: ActiveRecord - find MySQL connection/thread ID for query
On Aug 3, 1:24 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Michaël wrote: > > Hi, > > > Is it possible, when using a find method with a Model, to record the > > MySQL thread ID for the subsequent database query? Does ActiveRecord > > expose this? > > Why on earth would you need this? What are you trying to achieve? > > > > > Many thanks, > > Micha lBecause the application I''m maintaining uses Model find() methods to run large queries on the database to produce reports. These queries can take upwards of 10 minutes due to some complex table joins. While I''m altering the way these are working so they''re not taking a large amount of time, I need an interim solution where I monitor the database for any of these queries that are taking more than a set maximum time, killing the thread of those queries that are going over the threshold and recording which query was killed so it can be re-run at a quieter time. It would be really useful if, when one of these large finds is run, that I could record the thread ID it creates so if I need to kill a thread, I can match it back up to the originating find() call. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Aug-03 15:23 UTC
Re: ActiveRecord - find MySQL connection/thread ID for query
Michaël wrote:> On Aug 3, 1:24�pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> > Many thanks, >> > Micha l[Please quote what you''re replying to. It will make the discussion easier to follow.]> > Because the application I''m maintaining uses Model find() methods to > run large queries on the database to produce reports. These queries > can take upwards of 10 minutes due to some complex table joins. While > I''m altering the way these are working so they''re not taking a large > amount of time, I need an interim solution where I monitor the > database for any of these queries that are taking more than a set > maximum time, killing the thread of those queries that are going over > the threshold and recording which query was killed so it can be re-run > at a quieter time.Your database should already do this. You don''t need to do it from Rails.> It would be really useful if, when one of these > large finds is run, that I could record the thread ID it creates so if > I need to kill a thread, I can match it back up to the originating > find() call.If the database kills a thread, can''t you just rescue the appropriate exception? Best, -- Marnen Laibow-Koser marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Michaël
2010-Aug-03 15:33 UTC
Re: ActiveRecord - find MySQL connection/thread ID for query
> > It would be really useful if, when one of these > > large finds is run, that I could record the thread ID it creates so if > > I need to kill a thread, I can match it back up to the originating > > find() call. > > If the database kills a thread, can''t you just rescue the appropriate > exception?That''s a good point. I''ll try catching the exception and storing the find parameters so I can run that query at time when I can afford to. Thanks for the help, Michaël -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.