Solved

Restrict php cpu load

Posted on 2004-11-02
764 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
Question by:choccarlm
    12 Comments
     
    LVL 12

    Accepted Solution

    by:
    Hi choccarlm,
    Did you try "nice"? Or renice?

    Cheers!

    Stefan
    0
     

    Author Comment

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

    Thanks
    0
     
    LVL 12

    Expert Comment

    by:stefan73
    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
     
    LVL 12

    Expert Comment

    by:stefan73
    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
    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
    Sure, you can do that. It just depends which process should be a low-priority background process.
    0
     

    Author Comment

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

    Expert Comment

    by:stefan73
    "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
    ok so nice -n -20 would have a higher priority than nice -n 20 right?
    0
     
    LVL 12

    Expert Comment

    by:stefan73
    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
    - 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
    thanks a lot, much appreciated
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
    Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

    860 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now