Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Restrict php cpu load

Posted on 2004-11-02
12
Medium Priority
?
768 Views
Last Modified: 2013-12-16
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
0
Comment
Question by:choccarlm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 12

Accepted Solution

by:
stefan73 earned 2000 total points
ID: 12472477
Hi choccarlm,
Did you try "nice"? Or renice?

Cheers!

Stefan
0
 

Author Comment

by:choccarlm
ID: 12473448
No I havent tried that, how does it work and how would I run it?

Thanks
0
 
LVL 12

Expert Comment

by:stefan73
ID: 12474210
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:stefan73
ID: 12474233
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
 

Author Comment

by:choccarlm
ID: 12474363
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
 
LVL 12

Expert Comment

by:stefan73
ID: 12475350
Sure, you can do that. It just depends which process should be a low-priority background process.
0
 

Author Comment

by:choccarlm
ID: 12481238
so the lower the value (-20) the higher the priority?
0
 
LVL 12

Expert Comment

by:stefan73
ID: 12482998
"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
 

Author Comment

by:choccarlm
ID: 12483047
ok so nice -n -20 would have a higher priority than nice -n 20 right?
0
 
LVL 12

Expert Comment

by:stefan73
ID: 12484159
Yes, a LOT higher. I know of no system process which uses such a high priority. Be careful.
0
 
LVL 6

Expert Comment

by:admin0
ID: 12484323
- 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
 

Author Comment

by:choccarlm
ID: 12484458
thanks a lot, much appreciated
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question