Note that there are some explanatory texts on larger screens.

plurals
  1. POrails high memory usage
    text
    copied!<p>I am planning on using delayed job to run some background analytics. In my initial test I saw tremendous amount of memory usage, so I basically created a very simple task that runs every 2 minutes just to observe how much memory is is being used.</p> <p>The task is very simple and the analytics_eligbile? method always return false, given where the data is now, so basically none of the heavy hitting code is being called. I have around 200 Posts in my sample data in development. Post has_one analytics_facet.</p> <p>Regardless of the internal logic/business here, the only thing this task is doing is calling the analytics_eligible? method 200 times every 2 minutes. In a matter of 4 hours my physical memory usage is at 110MB and Virtual memory at 200MB. Just for doing something this simple! I can't even begin to imagine how much memory this will eat if its doing <strong>real</strong> analytics on 10,000 Posts with real production data!! Granted it may not run evevery 2 minutes, more like every 30, still I don't think it will fly. </p> <p>This is running ruby 1.9.7, rails 2.3.5 on Ubuntu 10.x 64 bit. My laptop has 4GB memory, dual core CPU.</p> <p><strong>Is rails really this bad or am I doing something wrong?</strong></p> <pre><code> Delayed::Worker.logger.info('RAM USAGE Job Start: ' + `pmap #{Process.pid} | tail -1`[10,40].strip) Post.not_expired.each do |p| if p.analytics_eligible? #this method is never called Post.find_for_analytics_update(p.id).update_analytics end end Delayed::Worker.logger.info('RAM USAGE Job End: ' + `pmap #{Process.pid} | tail -1`[10,40].strip) Delayed::Job.enqueue PeriodicAnalyticsJob.new(), 0, 2.minutes.from_now </code></pre> <h1>Post Model</h1> <pre><code>def analytics_eligible? vf = self.analytics_facet if self.total_ratings &gt; 0 &amp;&amp; vf.nil? return true elsif !vf.nil? &amp;&amp; vf.last_update_tv &gt; 0 ratio = self.total_ratings / vf.last_update_tv if (ratio - 1) &gt;= Constants::FACET_UPDATE_ELIGIBILITY_DELTA return true end end return false end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload