Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a Magento installation on a VPS that is giving me a headache.

This particular VPS has a reasonable spec - 2gb Memory and 50gb storage. It runs a single domain, with a single Magento install - and nothing else.

About 5 months ago we started having issues. Every so often (about once every 2 or 3 weeks) the VPS would crash - all processes stopped and the only way to restart the container is via Virtuozzo.

Now, however its 2 or 3 times a week. My VPS hosts confirm I am breaching the 2gb memory limit, at which point all VPS processes are killed to stop it bringing the entire node down.

I have not made any config changes to it at all - I was running New Relic on it for a short while, but have removed that in case it was contributing to the issues. I can see nothing in the logs which indicates an issue and we have no CRON jobs running at the time the crashes happen.

The site generates steady, but not huge amounts of traffic (averaging usually less than 100 visits per day)

Is there anything in particular I should have done to the Apache or PHP configs to help? Im not a massivley experienced Apache admin, but know more than enough to solve most problems...

Failing that, any other ideas that might help? Can't afford for this site to be down this much.

share|improve this question

migrated from stackoverflow.com Oct 10 '12 at 12:47

This question came from our site for professional and enthusiast programmers.

    
it all depends on the configuration and load on the server. MAgento does not need lot of visitors to hit the 2GB limit , see your memory configuration that is allowed for each request to use and do the math –  Anton S Oct 10 '12 at 10:40
1  
Consider not hosting a business critical website within a public Virtuozzo (or OpenVZ) VPS. –  Michael Hampton Oct 10 '12 at 13:42
    
and how big your product catalog is? –  Taras Chuhay May 24 at 21:44
add comment

4 Answers

One other useful thing to look at for setting the MAXCLIENTS is ApacheBuddy.

See https://github.com/gusmaskowitz/apachebuddy.pl

This basically looks through the stats and your configuration files and gives you a guideline as to what your MAXCLIENTS setting should be. To be honest I can never afford to go as low as they recommend but it is probably the "correct" answer.

To use/install:

wget https://raw.github.com/gusmaskowitz/apachebuddy.pl/master/apachebuddy.pl

perl apachebuddy.pl

Useful options include -p (for port if you are running varnish for example) and -P (that is a capital "P") to also take into account the PHP memory settings.

share|improve this answer
add comment

It's generally simple math on what to set in your apache config file. You have 2 gigs of ram and probably 1.5 of that can be used by apache.

so that's ~1,500 megs. Make sure your .htaccess file for magento is sane.

php_value memory_limit 128M php_value max_execution_time 120

(To be honest we have ours set to 512m because many users were getting blank pages. Go read var/log/exception.log to see if that's the case)

In this scenario you can only support a MaxClients of 12! And to be honest I think magento default memory limit is now 256. Which would imply maxclients of 6! I would also suggest using less MaxRequestsPerChild. Perhaps as low as 100. What I would see is a few processes getting bigger and bigger. Apache children do not free up memory until they are destroyed in my experience. That is what this setting will do. Respawn the child process after 100 requests.

I have had lots of problems with apache. We have servers with 7 gigs that fall over like you have described. Our traffic is much greater than yours though.

I just saw you ran mysql on this box too. Not good. You may want to look into running nginx with php-fastcgi. I got it working pretty well and it uses much less memory. Our only deal breaker was we had an extension that uses ioncube that we needed and I could not get to cooperate with it. (I also used xcache instead of apc as our opcode cache because I heard apc will not share memory between the cgi processes)

I have also used nginx as a reverse proxy to serve all static content. That may also work for you. This was much better and we used it for a long time until we decided to implement varnish.

At the very least you need to implement some kind of caching solution for magento.

share|improve this answer
add comment

You may wish to try apache-mpm-worker with php5-fpm instead. I noticed a drastic difference when I switched from the standard prefork/mod_php combo.

A few other suggestions:

  1. Check you mysql configuration by running the tuning-primer.sh script. This will provide a good baseline to ensure your mysql is configured properly and you aren't wasting memory on it.

  2. Are you taking advantage Magento's compilation and caching components?

  3. As you only have 2GB of RAM available, ensure that your Apache MaxClients is at a reasonable level. Start with a low number (e.g. 25) and monitor your RAM usage to see if you can increase that some.

  4. 2GB isn't a lot of memory for a Magento server with a decent amount of traffic. Have you looked into increasing the RAM or perhaps getting a second server to use for dedicated mysql to free up that RAM for Apache?

  5. Have you verified using a log analyzer (e.g. webalizer, awstats, etc) or possibly even just Apache's extended status module that Apache is the problem at the time of the excessive memory usage?

share|improve this answer
add comment

Few things I can think of right now:

1) Check that you are running prefork MPM and not worker MPM 2) Edit apache2.conf (on Debian is's located under /etc/apache2/apache2.conf:

Make sure the following config is there (appears to be best for us:)

Timeout 30
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 2

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          10
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   2000
</IfModule>

3) Look at using Varnish as a caching mechanism which will reduce the Apache load 4) Install APC/Memcache

share|improve this answer
    
Many thanks - ok, am definitely running mpm-prefork and already have APC installed. Will check out Varnish as well - will this run alongside APC ok? Have tried to implement your apache conf in my vhost.conf (as I am running under plesk). When restarting apache I get an error about 'startserver not allowed in section'... –  cheshirepine Oct 10 '12 at 9:57
1  
Yes Varnish will run alongside APC. Make sure to use the module they have too: magentocommerce.com/magento-connect/… –  KennyDs Oct 10 '12 at 10:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.