On Feb 24, 9:23 pm, William Fisk <[email protected]> wrote:
> Has anyone experienced an ActiveRecord query being much much slower than
> running the equivalent
> query in the MySql console?
>
> I am running a simple "group by" query with one condition on a table with 7
> million records.  When
> I run EXPLAIN it says that it will have to scan over all the records - well
> that's OK.  In the MySQL
> query it takes 1min 40secs which is OK for me - this is not a web app.  But
> when I run exactly
> the same query in a ruby script using ActiveRecord it takes about 45 mins -
> far too long.
>
I'd try using ruby-prof to see where the time is being spent (bear in
mind that ruby-prof does slow down the execution of ruby code, but it
should still give you an idea)

Fred

> I am running all this on my work PC, 3 gig of memory.  Windows PerfMon says
> I have 2 gig available
> and 1 gig on standyby.  I am using ruby 1.8.7; rails 3; mysql2 gem; Windows
> 7 and MySql 5.5.
> I have also set the INNODB buffer pool size to 480M.  
>
> What seems to be happening is that the MySQL process uses all the memory up
> to 500M and
> there is a lot of page swapping.  PerfMon shows that the disk activity is
> very high (99%). So
> that explains the bottleneck.  But I still don't know why this happens when
> I run the code from
> Ruby and yet from the MySQL console it is fine.
>
> I even tried just using the MySQL2 gem directly in my ruby code using
> MySql2::Client.new,
> but still very very slow.
>
> I know this probably doesn't explain everything but I just wondered if
> anyone had a similar experience.
>
> Thanks
>
> William
>
> p.s. also posed on 
> StackOverflow.http://stackoverflow.com/questions/5004204/query-is-fast-in-mysql-but...

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to