Select Page

Apache high memory usage – 5 easy ways to fix it

Apache is popular, but it often gets a bad rap for poor performance.

Apache high memory usage is found to cause of slow sites, page timeouts, mail bounces and more.

And here at Bobcares, our Support Engineers help web hosts, digital marketers and other online businesses keep their Apache servers super fast and stable.

Today, we’ll go through the top 5 reasons we’ve seen for Apache high memory usage and how we fix them.

 

How to reduce Apache’s high memory usage?

Apache comes with a lot of default settings.

And these default settings unintentionally become one of the major causes for the high memory usage.

For e.g., By default, most Apache softwares come with Prefork module. But for high traffic servers Worker MPM is the better option. So, by tweaking the settings as per the actual requirement of the customer, we can reduce the memory usage and increase the performance.

Note – Apache settings are subjective to web-traffic volume and system resources. So, prior to making changes, there needs to be a careful analysis.

It is at this point that things can get really technical. Click here to have our experts at Bobcares do the fine tuning for you so that you don’t have to lose sleep over it.

 

Let’s take a look at how we reduce Apache high memory usage at Bobcares.

 

1. Minimize Simultaneous Connections

When simultaneous connections increases, the amount of RAM Apache uses also increases.

Some of the parameters that we tweak to reduce the number of simultaneous connections are :

  • MaxClients
  • MaxSpareServers
  • MinSpareServers
  • StartServers
  • MaxRequestsPerChild
  • KeepAlive
  • KeepAliveTimeout
  • TimeOut

For e.g., MaxClients sets the limit on the number of simultaneous requests that can be supported by Apache webserver. So, if it is too high, it can overload the memory. We calculate an ideal value for MaxClient based on the available RAM and process size.

Similarly, KeepAlive is used to keep a single connection alive to transfer all the files to load a page. This saves the time in establishing a new connection for each file and helps to speed up Apache. But while the connections are kept open, they occupy RAM that could be used for other services.

So, to ensure there is no resource wastage, we set the value of KeepAliveTimeout to 2-5 seconds in low-traffic and 10 seconds in high-traffic webservers.

Click here to have our experts preform these tweaks while constantly monitoring for any configuration issues that may pop up.

 

2. Replace Prefork with Worker MPM

Prefork is the default module for Apache. It uses multiple child processes. Each child handles one connection at a time.

But the memory usage with Prefork is high.

So, if you have a high traffic, then the corresponding memory usage will be excessive.

In such cases, Worker MPM is the better option. It uses multiple child processes with many threads each. Each thread handles one connection at a time. So, the memory footprint is comparatively lower.

 

3. Reduce the number of modules

Although there may be a lot of modules that you are currently using, you may not actually need all of them.

And Apache loads all these modules to server memory.

For e.g., Consider the following modules which are loaded by default on CentOS 6.x.

  • proxy_balancer_module (shared)
  • proxy_ftp_module (shared)
  • proxy_http_module (shared)
  • proxy_ajp_module (shared)
  • proxy_connect_module (shared)
  • cache_module (shared)

If any of these are not needed, we can disable them to reduce the memory usage.

NOTE – Before you disable modules, ensure to keep a backup. In this way you can revert the changes if needed. Also, along with disabling  modules, make the corresponding changes in the config file. Otherwise it may show errors. If you would rather have us do these optimizations for you, then click here to talk to our experts.

 

4. Reduce Log level

Apache generates a lot of log info depending on how busy the site is.

If you have alternate ways to gather visitor data (eg. Google Analytics), the memory usage can be reduced by logging only error messages instead of all access logs.

Another alternative is to use Piped Logging, where Apache passes the log data to an external process (like logrotate). This can also minimize Apache’s memory footprint.

 

5. Optimize PHP and MySQL

Web servers rarely function alone. And often, an issue with the underlying PHP or MySQL is taken as memory issue with Apache.

So, if even after making the configuration tweaks in Apache doesn’t resolve the high memory usage, we look for the probable cause in other places.

For e.g., By default Apache uses mod_PHP. But by using PHP-FPM we can limit the memory consumption and also improve performance.

Similarly, in MySQL we can adjust the Key buffer size, Query Cache, Table Cache parameters etc., to reduce the memory usage.

 

Conclusion

Apache high memory usage can have an adverse effect on performance. In this post, we have discussed the various techniques our experts at Bobcares use to reduce the high memory usage.


PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

Submit a Comment

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

Bobcares
Bobcares is a server management company that helps businesses deliver uninterrupted and secure online services. Our engineers manage close to 51,500 servers that include virtualized servers, cloud infrastructure, physical server clusters, and more.
MORE ABOUT BOBCARES