I have a site which has been built in modx and when its hit with load uses up all cpu processing power and top is showing a lot of defunct php zombie processes consuming this.
Here's the system specs...
PHP 5.2.14
php running as suPHP
Mysql 5.1.51
Apache 2.0.63
modx 1.0.4
For testing im using ApacheBench and simulating 500 connections with 100 concurrent connections
I've tested this out 2 ways now...
Turning off .htaccess and stress testing a simple php page that just echoes 'Hello world'.
In top this shows php going defunct and turning into a zombie but they go away pretty quickly
Calling a page served by modx, where php is doing a lot more, spawns more zombies that eat more cpu and some of them dont go away quickly.
What would be causing this? Would it be a mistake in our code - in which case why does the simple Hello World script spawn zombies?
Is it some problem with server config or with putting too much load on the server?
Scratching my head about this all now and hoping for some pointers as to what to do next.
A process is “zombie” (which in top appears as Z) immediately after it exits (normally or not) Its process ID stays in the process table until its parent waits on (or “reaps”) it. Under normal circumstances, when the parent process sets up a signal handler for SIGCHLD so that, when the signal is sent (upon a child process's exit), the parent process then reaps it at its convenience.
If the parent process has hung for some reason, such as if it's suspended, or is too busy, or is deadlocked, then child processes that exit will not be reaped (until the parent process resumes again).
Usually, the main Apache process will reap any of its workers that exit. However, on a heavily-loaded server like you describe, the main process may not have enough time available to it to do this reaping. Unreaped (“zombie”) processes show up as in top.
In this case, the processes are normal and are not of concern, unless there are many, many unreaped processes.
When your test is over, do the zombie processes disappear after a short time? if so, you have nothing to worry about everything is normal.
By default, apache is set up for worker processes to exit after handling a limited number of requests. This is designed to not allow memory leaks to get out of hand. You might find tweaking this setting might help you.
First, to boost performance, you can put the information from your .htaccess file in apache main config file. Every time the directory which contains the .htacess, is being accessed it will read and load the .htaccess file unlike putting rewrite rules in you apache config, which is only loaded once, during startup.
About the php problem - if never heard about suPHP, but you could rather run fastcgi in conjunction with apache or - switch to fpm/nginx. I've been using it for a month now and it's much faster than Apache. I mean 2-3 times the performance.
Nginx has all the features Apache has. So rewrite rules, htaccess like security.