Command-line PHP script CPU usage goes sky-high, stays there--why?

Command-line PHP script CPU usage goes sky-high, stays there--why?

am 10.12.2007 21:42:16 von m5

Hello,

I have a command-line PHP script--called Listener--that is designed
to run indefinitely with a predictable CPU usage and memory
footprint. In a nutshell, it's a multi-client socket server that
waits for incoming connections, processes incoming data, stores
results in a MySQL database, and basically gets on with its life. And
it works. No errors or serious problems to speak of. And I've been
running it for a couple years on an Xserve dual-G5 2GHz w/ OS X
Server 10.4.11). Six months ago, the program would run for days, even
a couple weeks, without a hitch. The only reason I would stop the
script is for some other purpose, like a software update.

However, the number of socket clients connecting in the past 3-4
months has steadily increased, and this seems to have exposed (if not
created) a strange performance "issue" with PHP 5.2.4, MySQL 5.0.45
and/or Mac OS X Server 10.4.11. (I say "and/or" because I am unsure
where the problem's cause really lies.) Basically, after the script
has been running for a day or so (processing essentially the amount
data that used to take two weeks), the CPU usage of the machine goes
from 30% (normal) to 80-90%. This appears to be irrespective of the
number of clients connected to the server at the time, but rather the
amount of time the script has been running (and therefore cumulative
cycles it's operated, data processed, MySQL queries executed, etc.).
And the CPU usage stays high, even when the actual load (number of
clients) decreases. At this time, if I run top, I get the following
info:

22512 mysqld 91.6% 8:22:12 31 106 125 305M+ 3.20M
260M 475M
17104 php 7.2% 81:14.01 1 15 145 5.08M 7.80M
10.9M- 87.5M
22537 Terminal 6.6% 2:59:59 22 176 240 12.3M 21.2M
18.3M- 236M
[...]

At first I thought, okay, it's MySQL's fault. Maybe a lot of slow-
running queries. But the slow query log is pretty clean. So maybe
it's a combination of Mac OS X and MySQL and PHP? I Googled for a
similar problem, and finally ran across this article:

http://www.shawnhogan.com/2005/10/mysql-problems-on-mac-os-x -server.html

....where the author describes a very similar CPU usage pattern. I
tried his suggested fixes and they seemed to have helped a little (or
maybe it's my wishful thinking--hard to tell), since the high CPU
load issue doesn't appear to happen as soon... But it still happens.

Anyway, I'm really stumped as to what to do next, where to look, etc.
If I stop the script, and restart it (but not the MySQL itself), CPU
usage goes back to normal--for about a day or two.

The only thing I thought might be connected is how many short-lived
PHP child processes Listener creates--around 20-30,000 per day.
Sounds higher, but on average it's just one every 2-3 seconds.
Anyway, although the number of child processes isn't concurrent,
would there be a problem with the number of historical child
processes in view of ulimits or kern.maxfilesperproc?

Anyway suggestions, tips, or links are much appreciated. Thanks.

....Rene

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Command-line PHP script CPU usage goes sky-high, stays there--why?

am 10.12.2007 22:24:20 von Dee Ayy

The only thing that comes to my mind about this is to create a table
index. Just a thought.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php