RFE: Let's be nice!

Also posted in the Virtualmin forum:

Some of our users are starting to complain about delays and timeouts on our server, especially on the hour and right after midnight. Let's face it, there are a huge number of tasks running out of cron, and the list has been growing as new features and new clients are added. Some of these jobs are scheduled at random times, which helps a lot, but the real resource-intensive ones are causing an impact on the system at set times every day or every hour.

I think I have a solution: Let's be nice! Instead of running these jobs at the normal priority and making the users compete with them, let's schedule them at a lower priority. In particular, the following jobs seem ripe for this treatment:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * nice /etc/webmin/status/monitor.pl
0,10,20,30,40,50 * * * * nice /etc/webmin/quota/email.pl
0 * * * * nice /etc/webmin/virtual-server/bw.pl
@hourly nice /etc/webmin/virtual-server/quotas.pl
@daily nice /etc/webmin/virtual-server/backup.pl

For now, I have simply added the word nice in front of the command name in cron, but there may be a better way to handle this. Also, I want to make sure that the various Webmin/Virtualmin modules recognize this when automatically scheduling jobs so they don't get overwritten, or worse, duplicated with a whole second job.



I am reopening this bug since I can't see the comments that resulted in its correction and we're having problems with background processes. Backups (gzip), awstats.pl and webalizer launched from root's crontab are competing directly with webserving php processes and causing error 500 to happen from time to time.

I suggest that Virtualmin launches all these background processes with nice -n 19 so that they wait for the load to go down instead of taking over the CPU.

ghomem - you can set the nice level for all Virtualmin background processes at Webmin -> Webmin Configuration -> Advanced Options.

Does that work for you?

It doesn't change anything on root's crontab (crontab -l -u root) where the scheduled processes lie.

That's correct .. the nicing is implemented within Virtualmin's processes.

But it is Virtualmin that sets up awstats, webalizer and vhost backups. Can I has that as an enhancement those processes can also get custom priorities?

As I said they are competing with crtitical processes in our machine.

So the nice level will apply to awstats, webalizer runs and virtual server backups too.

Or do you want to have different cron jobs use different nice levels?

It should be enough to have a prio setting for awstats, webalizer, backups and other background jobs.

Have in mind that the prio must be inherited (ex backup.pl -> gzip).

Yes, as far as I know the nice level is always inherited by sub-processes.

So in your case, which background tasks would you like to be niced down and which would you keep at the regular priority?

As far as I remember the CPU intensive tasks are webalizer, awstats and backups (backup.pl, gzip). Maybe there are more that I don't remember now.

Ok .. so what not just nice all background tasks then? This will include all webalizer and awstats runs, as well as backups. The Virtualmin UI, webserving, mail, etc.. will then get a higher priority.

Seems to make sense. You could maybe get more feedback from other users / developers. If we all agree please implement.

Thanks! :)

So if you just want to nice all background processes, you can do this at Webmin -> Webmin Configuration -> Advanced Options. This will effect awstats, webalizer and backups, but not the Virtualmin UI, Apache, BIND, Postfix and other interactive services.

You mean "will effect..." on the next release, right?

Currently it doesn't.

Just a case study: we had some real issue with bw.pl. the script run every midnight till 10-12 AM so we added "nice -n 19" to it and it's helps a lot in the server performance. awstats and webalizer has not a big issues because that scripts finished very fast.