views:

415

answers:

2

Hi, i'm running a rails application with apache+passenger on virtual servers that do not have any swap space configured.

The site gets decent amount of traffic with 200K+ daily requests and sometimes the whole system runs out of memory causing odd behaviour on whole system.

The question is that is there any way to configure apache or passenger not to run out of memory (e.g. gracefully restarting passenger instances when they start using, say more than 300M of memory).

Servers have 4GB of memory and currently i'm using passenger's PassengerMaxRequests option but it does not seem to be the most solid solution here.

At the moment, i also cannot switch to nginx so that is not an option to preserve some room.

Any clever ideas i'm probably missing are welcome.

Edit: My temporary solution

I did not go with restarting Rails instances when they exceed certain amount of memory usage. Engine Yard wrote great blog post on the ActiveRecord memory bloat issue. This is our main suspect on the subject. As i did not have much time to optimize application, i set PassengerMaxRequests to 300 and added extra 2GB memory to server. Things have been good since then. At first i was worried that re-starting Rails instances continuously makes it slow but it does not seem to have impact i should worry about.

A: 

I would advise against restarting instances (if that is possible) that go over the "memory limit", because that may put your system in infinite loops where a process repeatedly reaches that limit and restarts.

Maybe you could write a simple daemon that constantly watches the processes, and kills any that go over a certain amount of memory. Be sure to log any information about the process that did this so you can fix the issue whenever it comes up.

I'd also look into getting some real swap space on there... This seems like a bad hack.

Fragsworth
You suggested and condemned the same thing.
Joey Robert
@Joey: Restarting a process is different from killing it
Fragsworth
A: 

I don't have a canned solution but you might want to use two commands that ship with Passenger to keep track of memory usage and nr of processes: 'passenger-status' and 'sudo passenger-memory-stats', see http://www.modrails.com/documentation/Users%20guide.html#_inspecting_memory_usage

evaneykelen
Tnx, i knew about these utilities and they've been helpful on monitoring the system. I modified my question with the current solution.
Priit