Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Ruby memory config go and how can one check if it is set?

In REE, and MRI 1.9+, ruby's garbage collector can be tuned:

  • http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning
  • http://smartic.us/2010/10/27/tune-your-ruby-enterprise-edition-garbage-collection-settings-to-run-tests-faster/
  • http://blog.evanweaver.com/articles/2009/04/09/ruby-gc-tuning/

But none of these articles say where to put this configuration. I imagine that if it's in the environment, ruby will pick it up when it starts -- however, there's no way to check this as far as I can tell. The settings don't show up in any runtime constants that I can find.

So, where do I put this configuration, and how can I double-check that it's being used?

like image 505
John Bachir Avatar asked Nov 13 '22 08:11

John Bachir


1 Answers

These settings are environment variables, so you would just need to set them in the parent process of the ruby process itself. Many people recommend creating a simple shell script for this purpose, perhaps calling it /usr/local/bin/ruby-custom:

#!/bin/bash
export RUBY_HEAP_MIN_SLOTS=20000
export RUBY_HEAP_SLOTS_INCREMENT=20000
...etc...
exec "/path/to/ruby" "$@"

The first few lines set whichever custom variables you want, and the last line invokes ruby itself, passing it whatever arguments this script was initially given.

You will next need to mark this script as executable (chmod a+x /usr/local/bin/ruby-custom) and then configure Passenger to use it as the ruby executable, by adding this to your Apache .conf file:

PassengerRuby /usr/local/bin/ruby-custom
like image 50
Stuart M Avatar answered Nov 15 '22 04:11

Stuart M