Optimizing RAM use for Apache (and LAMP in general)

March 25, 2016 306 views
Apache LAMP Stack Ubuntu

I scaled up from 1 GB to 2 GB, and after a while Apache made use of that RAM too. I guess that's as it should be with mpm_prefork using default settings, but documentation about how it works and how it is configured is very scarce.

So to the questions:

Does Apache take into account other applications' need for RAM, so that swapping doesn't occur even if an application might need 500 MB or more temporarily?

E.g. scaling large pictures via GD or ImageMagick can easily take 100 Mbyte per picture, and if resources are not immediately destroyed that can accumulate.

si and so are always 0, so at least during normal use it doesn't cause swapping.

Thanks in advance,

1 Answer

To the best of my knowledge Apache does not take into account other applications. If you're doing a large amount of image manipulation it might be a better solution to scale horizontally by setting up separate workers to do image manipulation tasks from the droplets serving the public pages and portions of your site.

  • Thanks for your response.

    As the scaling is done in PHP, doesn't PHP secure up to memory_limit? If not, any "naively configured" system could crash at any time.

    • Yes but this isn't a system-wide limit. The memory_limit setting in php.ini sets the per script limit but not the overall limit for the system. Each script being run will be limited to the memory specified there.

Have another answer? Share your knowledge.