Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Apache is using too much memory.
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Apache is using too much memory.

I recently got a 1024MB RAM VPS and I installed httpd,php,mysql and got a small webserver running. Now I find out that the current memory usage is 334.87/1024 MB... Why is Apache using so much memory? How can I optimize it to use as less memory as possible? Thanks

Here's a screenshot of top.

Comments

  • Apache is known to hog memory though. Switch to something else.

  • charliecharlie Member, Host Rep

    Switch to nginx + PHP-FPM

  • noosVPSnoosVPS Member
    edited August 2014

    Add varnish in front of apache and u will see masive improvement.

  • BlanozBlanoz Member
    edited August 2014

    If you want to use .htaccess rules: add nginx in front of Apache so that only dynamic content requests reach apache. Nginx has cache capabilities too, if you want to go that way and it's much easier to config. You could also use an Apache MPM version (Event or Worker) with PHP-FPM. Be sure to tune your FPM config.

    IF you don't need .htaccess rules, go along with nginx & PHP-FPM and never look back.

  • edanedan Member
    edited August 2014

    You can try to limit the server limit and max clients in httpd.conf (prefork), the default:

    StartServers       8
    MinSpareServers    5
    MaxSpareServers    20
    ServerLimit        256
    MaxClients         256
    MaxRequestsPerChild  4000
    

    Get the average httpd process using this:

    ps -ylC httpd --sort:rss | awk '{sum+=$8; ++n} END {print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n/1024"MB"}'

    and the MySQL memory usage:

    ps aux | grep 'mysql' | awk '{print $6/1024 " MB";}'

    Let say the average httpd process is 50MB and MySQL 100MB, and system resource eg. 100MB, so

    Total RAM - MySQL RAM usage - system resources / average httpd process = server limit and max cients.
    1024-100-100/50=16,48 or 16.
    

    So set the server limits and max clients to 16. This will prevent the use of swaps that will slow down the site loading.

Sign In or Register to comment.