Launching the garbage collection with Unicorn + Rack

I am trying to start out of range garbage collection (after the request has finished responding) in my Ruby on Rails application. I added the following to my config.ru:

# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) begin require 'unicorn/oob_gc' rescue LoadError, NameError end # Out-of-band GC, runs GC after every 10th request and after the response # has been delivered. begin use Unicorn::OobGC, interval=10 rescue NameError end run MyApp::Application GC.start 

However, I look at the NewRelic portal, and most web transactions show that an average of at least 110-150 ms is spent on garbage collection. Unicorn :: OoobGC should have done this outside the scope of the actual request? If so, why does this manifest itself in an online transaction? How do I get the time spent collecting garbage to occur outside the context of the web request in order to respond more quickly to customer requests? The time spent by the processor will still be the same, since it should happen in the background, but better in the background than maintaining the query pipeline.

+7
source share
1 answer

If one request allocates enough objects to start the GC, you will still see the gc time reported for the request, despite moving the final GC OOB with unicorn middleware.

With ruby ​​1.9.3 and REE, you can twist various GC knobs to control how often gc starts up. See Configuring GC in Ruby 1.9.3 for examples on setting RUBY_HEAP_MIN_SLOTS, RUBY_GC_MALLOC_LIMIT and RUBY_FREE_MIN for better behavior in long-term service applications.

+2
source

All Articles