crunz: High CPU usage
I used crunz with a php script of sending email (“yiic emailSpool loop” http://cornernote.github.io/yii-email-module). In this script, it’ll fetch spooled email (e.g 10 emails) from db and send them, then sleep 1 second, then next 10 emails,…
The problem is the schedule:run used very high CPU load
Pls look at process 84672

I did try to run yiic emailSpool loop without crunz
#yiic emailSpool loop &
and it only takes 0.1% cpu (the same result if i put this script to crontab -e)
Actually there isn’t many emails to send, most of the time this script hit db get 0 spooled emails, sleep, hit db, 0 emails, sleep, … but the server is always around 90-100% CPU load
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16
In the end i set probing time to 0,5s, IMO in Cron jobs this time can be set even to 1s. Issue is fixed and released in v1.5.1. Thanks @kinoute for tests and sample code.
Now my code (the one I shared earlier) is using less than 1% of my 2009 Mac Mini CPU! I think it’s perfect, thanks!
Thank you @kinoute, your samples was very helpful. IMO the problem was in the
EventRunner::ManageStartedEvents(), thewhileloop doesn’t had any(u)sleep. Could anyone test CPU usage on this version https://github.com/PabloKowalczyk/crunz/tree/fix-high-cpu-usage? In my tests usage reduced from ~30% to ~0,1% 😃I can do release even today if you confirm that my branch fixed issue.
A standard cronjob (like every 5 minutes) linked to a PHP script with a loop inside makes my CPU goes high.
Example (task):
loop.php (15 secs are enough to see the high CPU usage)
Running the loop.php file directly with “php loop.php” doesn’t trigger any increase of the CPU.
Link to the code to reproduce the bug: https://github.com/kinoute/crunz-bug