OpenVZ Apache mpm_worker Memory Issues

A lot of users look to run Apache’s mpm_worker rather than the prefork mpm as it’s regarded to be much more efficient than the perfork mpm.  Add in FastCGI rather than mod_php and it’s a great combination of stability as well as performance.  Unfortunately there is one issue with running this on OpenVZ and that is the stack size.  Even the modest VPS with very little traffic will end up using it’s allowed memory as well as it’s burst memory.  Many suggest just not running mpm_worker with OpenVZ but this is not the best solution.  The problem has to do with the default thread stack size of 8MB which with OpenVZ becomes real memory rather than simply virtual that will not actually be used by the system unless necessary.  There are several easy fixes for this:

The first one is to modify the init.d script of Apache to reduce the stack size.  So for a cPanel system it’ll be located at /etc/init.d/httpd and you’ll want to add the following:

ulimit -s 256

This will make the stack size just 256KB which will suffice for most users.  I prefer to just do this with Apache but if you like you could modify this globally by changing /etc/security/limits.conf or for all services you could change /etc/init.d/rc .  I believe though the best action is to just change Apache until you run into an issue with another service having the same issue.  As you may not want just 256 but higher for a specific service or the defaults are fine in other cases and lower may reduce performance.

Well I hope that helps everyone out to get the performance of mpm_worker while not having to deal with the memory issues with regards to the default stack size.

This entry was posted in Tips. Bookmark the permalink.

4 Responses to OpenVZ Apache mpm_worker Memory Issues

  1. mem says:

    Thanks for this useful suggestion. Will try out and see. How would I know if the 256KB stack size is insufficient?

  2. Tony says:

    When applications do not perform very good pretty much. Keep in mind this is just the default size allocated not what will be used.

  3. Vasiliy Faronov says:

    Thanks, Tony! This has made all the difference in the world. Total memory consumption went down from some 60M to just 20M.

  4. Naguissa says:


    Worked like a charm in a Ubuntu 10.10 amd64 OpenVZ VPS.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.