cpu overload

cpu overload

by Ray Le Couteur -
Number of replies: 9

Hi

I just had this message from my host relating to the cron.php script:


"This email is to warn you that your site is using too much cpu resources. Please make sure you are using an optimized script because a common cause for high cpu usage is a poorly written script. If the scripts below are not critical please discontinue using them"

Any suggestions? I only installed moodle a couple of weeks ago and I am only testing with about 8 users and 20 classes.

Could I include some usleep statements to slow the script down and make it use less resources (but take more time to execute?

 

Thanks in advance

Ray Le Couteur

Ray Le Couteur

Average of ratings: -
In reply to Ray Le Couteur

Re: cpu overload

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Not sure if sleep() functions will help, since the monitoring they are doing appears to be cumulative over time, and because that script is being run every five minutes it will stand out as a "heavy" script to their automatic program that is looking for such scripts. The actual CPU load from cron.php on EACH RUN is quite minimal. Sleep functions might only increase the work being done!

You could try reducing your cron period to something less often, like 10, 15 or 20 minutes.
In reply to Martin Dougiamas

Re: cpu overload

by Ray Kingdon -
I've gotta hold my hand up here! I thought Martin's 5 minutes was a bit excessive. The delay period before things like submissions and journal comments get emailed out is set by default to 30 minutes. So I thought, what the heck, another 30 minutes wouldn't matter and set my cron interval to 1 hour (that's an order of magnitude slower than recommended.) Even at that leisurely pace the cron script still appears in the log analysis but it's by no means the most hit page on the site. (For January it's in my top ten of Moodle pages but in the second half of that list.)

The question is: Is this 5 minute interval just to shift the emails quickly or is there something more fundemental going on here which needs such a frequent poke?
In reply to Ray Kingdon

cron period

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
There's nothing fundamental that necessarily "needs" the frequent poke. I chose 5 minutes so that things behave as expected, such as posts being sent out as soon as the editing time expires. The idea there is to keep lag down so that conversations are kept "hot".

By all means use a slower period. My feeling is an hour might be too slow, but I'll be interested to hear how it goes for you with a real class.

Note that you can avoid log entries by using the command-line version of php, and the CPU used by a particular run of cron.php is not much ... this server takes about .2 seconds each time.

In my experience 99% of CPUs these days are 99% idle 99% of the time. smile
In reply to Martin Dougiamas

Re: cron period

by Ray Le Couteur -

Thanks Martin

Seems to have cured the problem (at least in the eyes of my host).

 

Ray

In reply to Martin Dougiamas

Re: cron period

by Huib van Wees -
I like to put in my situation here, if it helps.

I'm running many things on one server.
Which is a C3 processor at 800 Mhz. with 131 MB of memory, but I'm planning to increase it to 512 MB or 1 GB.
The server is running 2 moodle instaltions (and many more things).

The first has 30 min. change time for the forums the second 15 minutes.(but that doesn't matter here I think)

Cron is set up like this:

0,15,30,45 8-23 * * * root /usr/bin/php /path_to_moodle_1/admin/cron.php > /dev/null
15,45 0-7 * * * root /usr/bin/php /path_to_moodle_1/admin/cron.php > /dev/null
3,18,33,48 8-23 * * * root /usr/bin/php /path_to_moodle_2/admin/cron.php > /dev/null
18,48 0-7 * * * root /usr/bin/php /path_to_moodle_2/admin/cron.php > /dev/null

Some little explanation on this:

I think it's not wise to run 2 cron.php's at the same time so there is a 3 minutes "delay" between both cron.php runs. I think only one minute delay will be enough, but I'm now to lazy to modify the crontab wink
Also the Moodle site will be used mostly during daytime, so:
At day time cron.php will run four times each hour.
At night the cron.php will "only" run two times each hour.
First I thought, why should I run it at night, but you'll never know somebody from downunder is visiting the website and post something into the forums wink

Hope this helps a bit.

Regards,

Huib


In reply to Huib van Wees

Re: cron period

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I like to put in my situation here, if it helps.

I'm running many things on one server.
Which is a C3 processor at 800 Mhz. with 131 MB of memory, but I'm planning to increase it to 512 MB or 1 GB.
The server is running 2 moodle instaltions (and many more things).


Great information for everybody. Sure it helps !!

Although your processor and memory configurations are a bit strange, ins't it !! big grin

Ciao.
Average of ratings: Useful (1)
In reply to Eloy Lafuente (stronk7)

Re: cron period

by Huib van Wees -
No it isn't tongueout

My workstation is also a C3 at 800 Mhz and I'm very happy with it.
It all in a mini-itx case and very complete!

About the memory... I made a mistake... mixed
It's 320 MB memory!
It was 256 MB and I had a left over 64 MB DIMM so put it in my server.


Regards,

Huib
In reply to Ray Le Couteur

Re: cpu overload

by Ger Tielemans -

If I create a course with lots of hyperlinks and texts on the week- or theme-cards of Moodle, I can even force a memory overload if My linux-admin I gives me 64Mb free for processes: Moodle even crashes.. (version 109)

It happens if I switch to edit-mode (without selection only one card to edit) 

In reply to Ger Tielemans

Re: memory overload

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Does it happen when you only have one section selected?

How many items are on this course page?

What are the specs of your machine?

And what does this have to do with cpu overload? wink