开发者

usleep() php5 uses 40% of idle CPU

开发者 https://www.devze.com 2022-12-24 20:04 出处:网络
Hi guys I have a weird question, I have a cli php script runs on Centos 5.x which uses usleep (somtimes 1sec, somet开发者_运维技巧imes 2sec, somtimes 100ms it depends) if there is some wait required,

Hi guys I have a weird question,

I have a cli php script runs on Centos 5.x which uses usleep (somtimes 1sec, somet开发者_运维技巧imes 2sec, somtimes 100ms it depends) if there is some wait required, but what I have noticed its that once on usleep() it seems to use about 40% of idle CPU:

Cpu(s):  5.3%us, 21.3%sy,  0.0%ni, 57.2%id,  0.0%wa,  0.0%hi,  0.0%si, 16.1%st

any ideas ?

cheers


This doesn't happen for me with a very simple testcase. Try the following on your system to see if you still get the excessive CPU time.

Script test.php:

<?php
for ($n=0;$n<1000;$n++)
{
  usleep(10);
}
?>

Then at the command line run: time php test.php

My results are as follows:

[ar@arctic ~]$ cat /etc/redhat-release 
CentOS release 5.2 (Final)
[ar@arctic ~]$ time php test.php 

real    0m1.020s
user    0m0.013s
sys     0m0.006s

You can see that the user and sys time are very very small in comparison to the real (or elapsed) time. i.e. CPU utilisation was very low.


Under Windows systems, if you do not set the time limit of the execution of your script to 0 (set_time_limit(0);), the php executable will eat as much as 50% CPU power when using sleep or usleep functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号