Default REE garbage collector settings are not really cool. Add these environment variables:
RUBY_GC_MALLOC_LIMIT=50000000
RUBY_HEAP_MIN_SLOTS=500000
RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
RUBY_HEAP_SLOTS_INCREMENT=250000
(these values are mentioned in documentation as a Twitter's example).
Result is very cool: having 5000-7000 requests per minute:
1. Load Average went down from 6-7 to 2.5, which is really cool
2. Average Response Time went down from 100ms to 70ms
3. CPU usage reduced twice
But memory usage went up (with memory leaks). To protect your web application from that - gently restart your workers every X requests. We use Passenger, so here is a config example:
PassengerHighPerformance on
PassengerPoolIdleTime 0
PassengerMaxRequests 2000
PassengerStatThrottleRate 2
RailsFrameworkSpawnerIdleTime 600
RailsAppSpawnerIdleTime 600
PassengerUseGlobalQueue on
PassengerMaxPoolSize 24
So, each passenger worker is restarted on every 2000nd request. Memory graph for 30mins is displayed on image below:
With 1 small change 1 server can handle ~30% more traffic. We've even removed few servers from the cloud :)
