LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   usleep reduce CPU spikes ? (https://www.linuxquestions.org/questions/programming-9/usleep-reduce-cpu-spikes-564579/)

anjanesh 06-26-2007 08:05 AM

usleep reduce CPU spikes ?
 
Hi

Does the usleep() function reduce CPU spikes ?

Thanks

macemoneta 06-26-2007 10:13 AM

Well, sort of. When your process is sleeping, it's not using any CPU. Rather than worry about spiking the CPU, why not run CPU intensive operations at low priority?

anjanesh 06-26-2007 10:30 AM

Quote:

why not run CPU intensive operations at low priority?
low priority - hows that ?

I got to do all this to make sure the scripts dont run anything intensive on my shared-hosting company - otherwise they'll suspend the account for resource overuse on a shared a/c.

macemoneta 06-26-2007 10:39 AM

To lower the priority, you use 'nice'. However, if your shared hosting company requires you to keep your CPU usage low, get another hosting company. They should be capping/limiting your resource usage instead of having you do it. They appear not to have the skills needed to offer reliable service, and that will just bite you sometime in the future.

anjanesh 06-26-2007 10:50 AM

Quote:

However, if your shared hosting company requires you to keep your CPU usage low, get another hosting company.
- this is rule for all shared hosts - its our duty to keep it from using CPU for too long.

macemoneta 06-26-2007 11:02 AM

There are different ways to implement a shared host. Using a virtual private server allows the service provider to limit your access to the CPU to a fixed percentage. So while your virtual CPU may be a 100%, the real CPU may be at 10%. This is more complex to implement, but it also means that your hosting service isn't just thowing a bunch of people on a Linux box with no planning.


All times are GMT -5. The time now is 02:09 PM.