How do I fix Apache instability?

I have installed a simple LAMP package on Debian and I am having some problems with Apache webserver.

Every 3-4 hours, the web server is deadlocked and all requests that end up in the database block. The server creates a new child for each request. The number of processes is growing very quickly. After a few seconds, Monit notices that something is wrong and restarts the Apache server.

I suspect this issue is due to the way PHP handles the pool of database connections, because the server can still respond to static content requests. Have you experienced this behavior? What should I do?

Update: The issue has been resolved. It seems like a bad idea to use APC for caching code and user data. I am now using Memcache for storing user data and APC for code only. I still get some segmentation errors from time to time, but the server is stable in most cases.

0


source to share


4 answers


I suspect the problems are:

  • Difficult long-term database query that blocks further queries. It's pretty easy if you are using the MySQL MyISAM engine, which only has table-level locking and readers can easily block writers and vice versa, so one complex query, say a user's tables, can pretty much block the entire server, while the database is waiting for I / O. You can usually diagnose this using "SHOW PROCESSLIST" or a tool that does it for you.
  • By setting MaxClients too high for the RAM available on the presale server, almost everyone does it. If you are using Apache "bold" prefork (eg with in-process PHP) then do not set MaxClients higher than you have enough ram. This is probably much less than the typical values โ€‹โ€‹of 100 or 150.


These two things conspire to cause the problem you are seeing. They both need to be fixed as they can cause problems on their own.

This is purely based on guesswork and experience.

+3


source


Why don't you take a look at the magazines? /var/log/apache2/*

is a good place to start. What is requested just before the server dies? From there, you can probably determine what's going on. Since by default php scripts exit after 30 seconds, the error has to be quite massive to trigger something like this.



+1


source


Check your timeout settings in / etc / apache 2 / apache2.conf file, I've seen similar problems when Timeout is set to high and the system ends up in a bunch of dropped connections.

+1


source


The mysql-slow log is also useful for finding slow problematic queries.

0


source







All Articles