WebFaction
Community site: login faq
1
4

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 06 Mar '11, 02:47

klynton's gravatar image

klynton
1.6k129
accept rate: 42%


Hi,

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

#!/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.

permanent link

answered 06 Mar '11, 02:49

klynton's gravatar image

klynton
1.6k129
accept rate: 42%

edited 06 Mar '11, 02:50

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

(17 Apr '11, 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/...

(17 Apr '11, 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:

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

You will want to change it to something like this:

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.

(17 Apr '11, 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" "$@"

(18 Apr '11, 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...

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

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

(24 Jan '12, 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?

(20 Aug '12, 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.

(21 Aug '12, 01:08) johns ♦♦ johns's gravatar image
showing 5 of 8 show 3 more comments

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.'

permanent link
This answer is marked "community wiki".

answered 05 Dec '12, 21:24

navy's gravatar image

navy
1
accept rate: 0%

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

(05 Dec '12, 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
(06 Dec '12, 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!

(06 Dec '12, 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.

permanent link

answered 06 Dec '12, 16:10

navy's gravatar image

navy
1
accept rate: 0%

Here's what I found, after looking at the number of running RackApp .../redmine isntances and seeing all the memory they were consuming, I needed more of a solution than above. I received a message from WebFaction that my process was killed as it was consuming way too much memory. After doing some testing, I found doing even simple things in Redmine was running up to 5 instances!

I need Redmine for client access, but my use is very minimal. I did some Googling and found this: http://blog.phusion.nl/2013/03/12/tuning-phusion-passengers-concurrency-settings/

Here's what I added to http section in the nginx.conf file:

passenger_min_instances 1;
passenger_max_pool_size 1;
passenger_spawn_method direct;

It seems to be doing what I need. This is all new for me though (I'm a Windows/Android developer, no experience with RoR/Ruby/Phusion, etc), so feedback/corrections welcome!

permanent link

answered 27 Jul '13, 10:33

RickB's gravatar image

RickB
1
accept rate: 0%

Your answer
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

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×105
×82
×79
×46

question asked: 06 Mar '11, 02:47

question was seen: 10,169 times

last updated: 27 Jul '13, 10:33

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2017 PARAGON INTERNET GROUP LIMITED
WEBFACTION IS A SERVICE OF PARAGON INTERNET GROUP LIMITED
REGISTERED IN ENGLAND AND WALES 7573953 - VAT REGISTRATION NUMBER 182147021
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM