choccarlm
asked on
Restrict php cpu load
Hi, Im running Mandrake 9.2 and php 4.
I am also running a few game servers and I generate player stats for these servers using php. Whenever php runs on the server, it uses 99% of the cpu and causes the gameservers to lag and people often leave the server because it becomes unplayable for about a minute whilst php is running.
Is there anyway to restrict the amount of cpu usage php gets so it wont cause lag on the game servers when its running?
Thanks
I am also running a few game servers and I generate player stats for these servers using php. Whenever php runs on the server, it uses 99% of the cpu and causes the gameservers to lag and people often leave the server because it becomes unplayable for about a minute whilst php is running.
Is there anyway to restrict the amount of cpu usage php gets so it wont cause lag on the game servers when its running?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
choccarlm,
You can either do
nice -[numeric value 1-20] command ...
Example: nice -20 apache
...or you can re-nice existing processes:
renice 20 pid ...
Such as:
ps -ef | grep apache | awk '{print $2}' | xargs renice 20
You can either do
nice -[numeric value 1-20] command ...
Example: nice -20 apache
...or you can re-nice existing processes:
renice 20 pid ...
Such as:
ps -ef | grep apache | awk '{print $2}' | xargs renice 20
The "nice" value affects CPU scheduling. You can see that with the "top" tool:
top -I
Processes with a higher nice value don't get an equal CPU share on a fully loaded machine. You could also use negative nice values for your game server when using root, but I wouldn't recommend that. Example:
renice -5 <server_pid>
top -I
Processes with a higher nice value don't get an equal CPU share on a fully loaded machine. You could also use negative nice values for your game server when using root, but I wouldn't recommend that. Example:
renice -5 <server_pid>
ASKER
so nice -n 19 command would mean that the command being called would get less priority than other running commands?
Could I also start all 3 of my gameservers using the nice command? I.E
nice -n -20 /bin/gameserver1
nice -n -20 /bin/gameserver2
nice -n -20 /bin/gameserver3
and the stats using
nice -n 20 /bin/stats1
nice -n 20 /bin/stats2
nice -n 20 /bin/stats3
Could I also start all 3 of my gameservers using the nice command? I.E
nice -n -20 /bin/gameserver1
nice -n -20 /bin/gameserver2
nice -n -20 /bin/gameserver3
and the stats using
nice -n 20 /bin/stats1
nice -n 20 /bin/stats2
nice -n 20 /bin/stats3
Sure, you can do that. It just depends which process should be a low-priority background process.
ASKER
so the lower the value (-20) the higher the priority?
"nice -20" is equivalent to "nice -n 20" - it's a positive number. a numeric -20 would be --20. And yes, a negative nice value means a higher priority (a "less nice" process). Only root can lower the nice value.
ASKER
ok so nice -n -20 would have a higher priority than nice -n 20 right?
Yes, a LOT higher. I know of no system process which uses such a high priority. Be careful.
- means higher priority
+ means lower pririty
Here is a table:
-19 = highest
-18
-17
-16
..
-2
-1
0 - normal priority
1
2
..
16
17
18
19 - lowest priority!
Kernel won't allow a -20 .. -19 is the max you get i think.
+ means lower pririty
Here is a table:
-19 = highest
-18
-17
-16
..
-2
-1
0 - normal priority
1
2
..
16
17
18
19 - lowest priority!
Kernel won't allow a -20 .. -19 is the max you get i think.
ASKER
thanks a lot, much appreciated
ASKER
Thanks