Tatva-Artha

meaning of "it"

Debugging Passenger Memory Issues

without comments

There was an interesting thread on ruby-passenger application server newsgroup recently: http://groups.google.com/group/phusion-passenger/browse_thread/thread/f48ad0eb018a2482

Here is my take away:

  # returns [class, count] tuples for all active records in the heap 
  def ar_space 
    GC.start 
    h = Hash.new(0) 
    ObjectSpace.each_object do |o| 
      next if o.__id__ == self.__id__ 
      next unless ActiveRecord::Base === o 
      h[o.class.to_s] += 1 
    end 
    return h.sort{|a,b| -(a[1]<=>b[1])} 
  end

Nifty little snippet to fetch number of active record objects on heap. I am guessing, incorporating this as Controller after_filter can help with cost of each request..

http://www.tatvartha.com/wp-content/plugins/sociofluid/images/digg_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/reddit_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/stumbleupon_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/delicious_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/google_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/twitter_16.png

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Written by Sharad

May 1st, 2011 at 1:05 pm

Posted in All

Tagged with , ,

Leave a Reply