A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearHow do I make php nicer to the CPU? - page 1
User InfoPosts
How do I make php nicer to the CPU?#1
I'm running on a shared *NIX server (run by Site5). I have a php script that runs in the background occasionally doing some offline calculations. It uses around 100% CPU while it runs. I've tried nice-ing it, like this:

nice -n 19 php script.php


but that doesn't seem to make any difference.

posted date: 2008-12-19 11:04:00


Re: How do I make php nicer to the CPU?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-19 11:04:01


Re: How do I make php nicer to the CPU?#3
Even niced, it'll use 100% CPU if available. However, the kernel will give priority to any other (non-niced) processes that come along.

posted date: 2008-12-19 11:09:00


Re: How do I make php nicer to the CPU?#4
Actually no-one's complained. I'm just paranoid, I guess. There was a time last week when the server became almost unusable, and it looked like it was because someone was running a perl script which was hogging CPU and memory. So I was afraid I might be causing the same problem for other users now.

posted date: 2008-12-19 11:23:00


Re: How do I make php nicer to the CPU?#5
As long as the system is responsive, and you are able to get other work done while it's running, I wouldn't worry about it. I run a distributed computing client on my systems, and it soaks up any available CPU cycles. Since it runs with the lowest priority, any and all other processes will preempt it as needed.

posted date: 2008-12-19 11:40:00


Re: How do I make php nicer to the CPU?#6
Ah. Now I realise that all that was happening here was that I was forgetting exactly what nice does. Thanks for the useful reminder! :-)

posted date: 2008-12-19 11:44:00


Re: How do I make php nicer to the CPU?#7
As your process is background, and uses 100% CPU it seem that the process is cpu bound. It is background so user bound would not be expected, so the only alternative would be IO bound. If your process should not really do interesting IO, the script itself would be expected to be CPU bound, and not just buggy.Processes will always try to go as fast as possible. If they are IO bound, they will use 100% IO, if they are CPU bound, they will try to use 100% CPU. Properly written process schedulers automatically aim to provide a sense of fairness to all processes, meaning that the bigger processes get lower priority. You can further lower the priority with nice. The fact that the cpu usage is still about 100% means that there are no other processes which are currently CPU bound, but are most likely waiting for input from the network.

posted date: 2008-12-19 12:39:00


Re: How do I make php nicer to the CPU?#8
Nice changes how often your php results in 100% CPU, if there are considerable processes to context-switch, not how much.The moment a program executes a system call, the kernel can yield the CPU to another process before doing the real job. Your php doesn't seem to make any system call when it's running full speed. That is, you're not making any blocking I/Os (socket, file, etc.) See if any code block is stuck in busy-waiting.

posted date: 2008-12-19 13:38:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.