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
choccarlmAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
stefan73Connect With a Mentor Commented:
Hi choccarlm,
Did you try "nice"? Or renice?

Cheers!

Stefan
0
 
choccarlmAuthor Commented:
No I havent tried that, how does it work and how would I run it?

Thanks
0
 
stefan73Commented:
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
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
stefan73Commented:
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>
0
 
choccarlmAuthor Commented:
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
0
 
stefan73Commented:
Sure, you can do that. It just depends which process should be a low-priority background process.
0
 
choccarlmAuthor Commented:
so the lower the value (-20) the higher the priority?
0
 
stefan73Commented:
"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.
0
 
choccarlmAuthor Commented:
ok so nice -n -20 would have a higher priority than nice -n 20 right?
0
 
stefan73Commented:
Yes, a LOT higher. I know of no system process which uses such a high priority. Be careful.
0
 
admin0Commented:
- 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.

0
 
choccarlmAuthor Commented:
thanks a lot, much appreciated
0
All Courses

From novice to tech pro — start learning today.