[LRUG] Request for assistance with Rails performance oddity
John Winters
john at sinodun.org.uk
Sun Oct 31 02:03:26 PDT 2010
On Sat, 30 Oct 2010 13:50:35 +0100, Roland Swingler
<roland.swingler at gmail.com> wrote:
>> Is there a way of telling ActiveRecord to discard any cached database
> records it currently has in memory?
>
> I don't think you can quite do this - although you can rely on the
> ruby garbage to collector to remove any objects that you no longer
> need, so you could just re-find your root record if that is all you're
> really interested in.
I don't think this is an area where the Ruby garbage collector can help.
It appears that ActiveRecord is caching the retrieved records internally,
and then scanning through them later. Because there are so many it slows
the processing down dramatically.
> @category = EventCategory.find(whatever)
> # your code to remove specific events
> @category.events.each { .... }
> @category = EventCategory.find(whatever)
>
> The original EventCategory will no longer be referenced anywhere
> (hopefully), and neither will any of the events, so the memory they
> use will be reclaimed.
This is precisely what I'm doing, but it appears the records are still
referenced and accessed internally within ActiveRecord. Memory isn't an
issue, but having the code repeatedly scan the cached records is.
> Will this do what you mean?
I don't think so.
> You're probably better off implementing an efficient way of removing
> the events within a certain range though, rather than trying to work
> around the problem like this.
Yes indeed - I fully intend to do fix the earlier event purging to do it
properly. I'd still like to know how to fix this too though. I've noticed
my application does slow down quite unpredictably at times and as there are
occasions when the Rails app loads large numbers of records (from other
tables) during the course of its normal running, I'm wondering whether this
same phenomenon would explain that slow-down too.
John
More information about the Chat
mailing list