title: Can i limit apache+passenger memory usage on server without swap space
body: <p>i'm running a rails application with apache+passenger on virtual servers that do not have any swap space configured.</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>At the moment, i also cannot switch to nginx so that is not an option to preserve some room.</p>
  
  <p>Any clever ideas i'm probably missing are welcome.</p>
  
  <p><strong>Edit: My temporary solution</strong> </p>
  
  <p>I did not go with restarting Rails instances when they exceed certain amount of memory usage. Engine Yard wrote great blog post on the <a href="http://www.engineyard.com/blog/2009/thats-not-a-memory-leak-its-bloat/" rel="nofollow noreferrer" title="ActiveRecord memory bloat issue">ActiveRecord memory bloat issue</a>. 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.</p>