Apache / memory issue

I am having Apache and memory issues on my Linode 512, causing server to get high load and become unresponsive.

I am using APC + Apache 2 + PHP plus cloudflare service.

Everything works fine, server have monit on it, and have to restart server it load gets over 5 in 1 min load. Pingdom is checking the apache status to be sure server is up. Magic happens, everything gets messed up like, load increase to 70, %90 cpu is idle, and swap usage is %99.9, so basicly server gets out of memory.

Apache throws error:

> [error] server reached MaxClients setting, consider raising the MaxClients setting

[warn] child process 3589 still did not exit, sending a SIGTERM

[Thu Jul 14 02:16:47 2011] [warn] child process 3592 still did not exit, sending a SIGTERM

[Thu Jul 14 02:16:47 2011] [warn] child process 3598 still did not exit, sending a SIGTERM

[Thu Jul 14 02:16:47 2011] [warn] child process 3574 still did not exit, sending a SIGTERM

and i have to reboot linode. There is not much active site on server, mainly a wordpress site, but not active visitors at same time. Cloudflare is blocking most of the bots i hope.

My apache settings are :

Timeout 20
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15

 <ifmodule mpm_prefork_module="">StartServers          1
    MinSpareServers       1
    MaxSpareServers      3
    ServerLimit          100
    MaxClients          100
    MaxRequestsPerChild   4000</ifmodule> 

I am using prefork, should i switch that?

Just tell me if you need to have a look at any other .conf file.

I would be glad if you can guide me with some apache conf for my linode 512

my swap is : 512 mb

8 Replies

With php eating away at your memory MaxClients is probably way too high compared to how much memory you have.

This is probably a reasonable starting point for a low memory apache configuration: ~~[http://library.linode.com/troubleshooting/memory-networking#sphapache-2-low-memory-settings" target="blank">](http://library.linode.com/troubleshooti … y-settings">http://library.linode.com/troubleshooting/memory-networking#sph_apache-2-low-memory-settings](

thanks for link. but when i set it like that, prolly server will continue to throw "max client settings" error more and more right?

@barbaros:

thanks for link. but when i set it like that, prolly server will continue to throw "max client settings" error more and more right?

It's quite possible that it will hit the max clients roof more often, but it should not run the system out of memory to the point where it crashes.

Edit: To expand on that, you may want to reduce the keepalive timeout or disable keepalives altogether to not get too many client slots tied up for a long time as you lower the number of simultaneous requests being processed. Or do something more drastic and move away from apache with mod_php, so that you can serve more static content but still limit the php requests.

@hawk7000:

Edit: To expand on that, you may want to reduce the keepalive timeout or disable keepalives altogether to not get too many client slots tied up for a long time as you lower the number of simultaneous requests being processed. Or do something more drastic and move away from apache with mod_php, so that you can serve more static content but still limit the php requests.

What would be the best timeout for a situation like that?

And what you mean by move away from apache ? I already use mod_php on server with apache

@barbaros:

@hawk7000:

Edit: To expand on that, you may want to reduce the keepalive timeout or disable keepalives altogether to not get too many client slots tied up for a long time as you lower the number of simultaneous requests being processed. Or do something more drastic and move away from apache with mod_php, so that you can serve more static content but still limit the php requests.

What would be the best timeout for a situation like that?

And what you mean by move away from apache ? I already use mod_php on server with apache

Something low?

All this "lower MaxClients and disable keepalives" talk is to some extent a kluge to avoid the main issue which imo is that mod_php breaks the way that Apache httpd was intended to work. (Relatively slim, pretty much fixed size, worker processes serving files without having to suddenly gobble up tons of memory.)

So my point was more about moving away from mod_php than moving away from Apache httpd itself. (However, switching away from Apache httpd to eg nginx would quite probably provide additional benefit, but may not be desirable depending on other circumstances.)

Moving from modphp to a fastcgi approach for handling php (php-fcgi / php-fpm) with either Apache or some other httpd will likely make the biggest difference. You may want to look at eg ~~[http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html" target="blank">](http://2bits.com/articles/apache-fcgid- … ation.html">http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html]( for an illustration of how that makes a difference. (Not sure how good a guide it is, specifically the newer "fpm" may be desirable, but it explains the idea and has some graphs to show what the impact may be like.)

It also lets you limit the number of simultaneous php workers separately from the number of web clients (which would allow you to serve more static content while still limiting the number of memory hungry php processes).

Thanks for the link again.

To be honest, i tried nginx + fpm on my server, and at least for my wordpress site it caused site to load slower. Probably some config error i get pissed and switched to apache + mod_php.

I tried to use apache + fpm but couldnt managed to make it work together

@barbaros:

Thanks for the link again.

To be honest, i tried nginx + fpm on my server, and at least for my wordpress site it caused site to load slower. Probably some config error i get pissed and switched to apache + mod_php.

I tried to use apache + fpm but couldnt managed to make it work together

Ok, start out by lowering MaxClients and see if you can find a sensible balance where php doesn't exhaust all memory to the point where the system keels over and dies.

So same thing happened again, not sure the real reason again tho,

here is the screen shot of apache server status when its happened

http://i437.photobucket.com/albums/qq99 … itled2.jpg">http://i437.photobucket.com/albums/qq99/bonjurkes/Untitled2.jpg

Color groups reflects same domains, so red one is my wordpress blog, other ones are also wordpress but they are not active at all.

So I checked the apache log

[Mon Jul 18 10:55:16 2011] [error] server reached MaxClients setting, consider raising the MaxClients setting

Then server load raised up to 40 again and became unresponsive. It sounds a bit weird that I can barely host 1 wordpress site on my server and if too many requests made server blows up.

I checked my statpress and it show 3 recent ips at that request, one of them is legit user. Other one is 184.72.46.235 and 50.18.121.34 . And those both ips resolve to amazon.com service not sure why they visit my site.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct