login community faq
1
2

How can I reduce my Ruby/Rails memory usage when running Redmine? Redmine seems to use quite a bit of my plan's memory ~60MB on an empty project how can I reduce that?

asked Mar 06 '11 at 02:47

klynton's gravatar image

klynton ♦♦
149128


Hi,

Great question Klynton! ;) Here's a nice little wrapper script that you can use to reduce the memory usage for your Redmine project:

1
2
3
4
5
6
7
#!/bin/sh
export RUBY_HEAP_MIN_SLOTS=10000
export RUBY_HEAP_SLOTS_INCREMENT=10000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=500000
export RUBY_HEAP_FREE_MIN=4096
exec "ruby" "$@"

then just have nginx call this script instead of the ruby executable.

That will reduce your memory usage by ~20MB, at least.

answered Mar 06 '11 at 02:49

klynton's gravatar image

klynton ♦♦
149128

edited Mar 06 '11 at 02:50

This looks great. Which file does this go in, though? Sorry, I'm new to this...

(Apr 17 '11 at 23:04) Spike Spike's gravatar image

Hi,

You can put it in a file called ruby.sh then just point your nginx script to the full path to ruby.sh instead of /usr/local/bin/...

(Apr 17 '11 at 23:16) klynton ♦♦ klynton's gravatar image

There should be a line in the nginx.conf file in your rails application that looks something like this:

1
passenger_ruby  /home/username/webapps/rails/bin/ruby;

You will want to change it to something like this:

1
passenger_ruby  /home/username/webapps/rails/bin/ruby_small;

Then, create the new "ruby_small" file with the contents as Klynton described.

Lastly, set the permissions (chmod 755 ruby_small) so that it is executable.

(Apr 17 '11 at 23:17) ryans ♦♦ ryans's gravatar image

It worked, thanks! The only thing I needed to change on top of that was to change the last line:

exec "ruby" "$@"

to:

exec "/full/path/to/ruby" "$@"

(Apr 18 '11 at 08:53) Spike Spike's gravatar image

Will this work for a non-redmine project? I have a couple of rails 3.1 projects that are using an over abundance of memory that I need to get a handle on...

(Jan 24 '12 at 17:50) Kagi Kagi's gravatar image

Yes, it will work on other ruby-based apps too.

(Jan 24 '12 at 19:41) neeravk ♦♦ neeravk's gravatar image

Works well. But just wondering, it seems that Passenger ApplicationSpawner also sucks down a chunk of memory, and it eventually seems to spawn several redmine instances -- is that OK? Does this happen when the old instance runs out of memory? Is there any way to keep a lid of the number of instances spawned and what would the adverse effect be if any?

(Aug 20 '12 at 19:29) pixelglow pixelglow's gravatar image

@pixelglow, multiple process threads are normal. You may want to submit a support ticket so we can see what you are describing in real time.

(Aug 21 '12 at 01:08) johns ♦♦ johns's gravatar image
showing 5 of 8 show all

I did as following steps, but it does not work. Something wrong?

  1. Create the new "ruby_small" file with the contents as Klynton described in '/home/webapps/my_redmine/bin/'
  2. Set the permissions (chmod 755 ruby_small) so that it is executable.
  3. Change the line in the nginx.conf file 'passenger_ruby /home/username/webapps/my_redmine/bin/ruby;' with 'passenger_ruby /home/username/webapps/my_redmine/bin/ruby_small;'
  4. Restart Redmine with '~/webapps/my_redmine/bin/restart'

then, when I want to access my redmine, it tells me 'Cannot spawn application '/home/user/webapps/my_redmine/redmine': The spawn server has exited unexpectedly.'

This answer is marked "community wiki".

answered Dec 05 '12 at 21:24

navy's gravatar image

navy
1

Change the error log level in nginx's config file to 'debug' and check the nginx log for more info.

(Dec 05 '12 at 22:40) johns ♦♦ johns's gravatar image
  1. I changed nginx's config file to 'error_log /home/unigin/logs/user/error_unigin_redmine.log debug;'
  2. After restarted Redmine, error is the same. but there's no content in /home/unigin/logs/user/error_unigin_redmine.log
(Dec 06 '12 at 02:15) navy navy's gravatar image

Perhaps the ruby version for your app is different than the ruby that the new "ruby_small" is using? For example, your should already have $HOME/webapps/my_redmine/bin/ruby as a symlink to ruby, so maybe set the exec "ruby" "$@" line in "ruby_small" to explicitly use the same ruby.

You can also try modifying "ruby_small" so that it does nothing at all to modify the ruby environment and just passes through transparently. Once that is working, you can then see if one of the environment variables is causing the problem. Hope that helps!

(Dec 06 '12 at 02:47) ryans ♦♦ ryans's gravatar image

Thank you very much, ryans. I updated the call to the 'ruby' executable with the full path and it works.

answered Dec 06 '12 at 16:10

navy's gravatar image

navy
1

Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×79
×59
×58
×36

Asked: Mar 06 '11 at 02:47

Seen: 3,194 times

Last updated: Dec 06 '12 at 16:10

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited