Also posted in the Virtualmin forum:
http://www.Virtualmin.com/forums/virtualmin/trying-to-be-more-nice.html
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.
Comments
Submitted by ghomem on Wed, 11/25/2009 - 18:56 Comment #4
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.
Submitted by JamieCameron on Wed, 11/25/2009 - 19:02 Comment #5
ghomem - you can set the nice level for all Virtualmin background processes at Webmin -> Webmin Configuration -> Advanced Options.
Does that work for you?
Submitted by ghomem on Wed, 11/25/2009 - 19:10 Comment #6
It doesn't change anything on root's crontab (crontab -l -u root) where the scheduled processes lie.
Submitted by JamieCameron on Wed, 11/25/2009 - 19:53 Comment #7
That's correct .. the nicing is implemented within Virtualmin's processes.
Submitted by ghomem on Thu, 11/26/2009 - 04:39 Comment #8
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.
Submitted by JamieCameron on Thu, 11/26/2009 - 13:25 Comment #9
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?
Submitted by ghomem on Thu, 11/26/2009 - 13:51 Comment #10
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).
Submitted by JamieCameron on Thu, 11/26/2009 - 20:11 Comment #11
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?
Submitted by ghomem on Fri, 11/27/2009 - 04:17 Comment #12
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.
Submitted by JamieCameron on Fri, 11/27/2009 - 14:37 Comment #13
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.
Submitted by ghomem on Fri, 11/27/2009 - 17:10 Comment #14
Seems to make sense. You could maybe get more feedback from other users / developers. If we all agree please implement.
Thanks! :)
Submitted by JamieCameron on Fri, 11/27/2009 - 20:07 Comment #15
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.
Submitted by ghomem on Sat, 11/28/2009 - 22:12 Comment #16
You mean "will effect..." on the next release, right?
Currently it doesn't.
Submitted by smartvirtualmin on Wed, 04/14/2010 - 09:25 Comment #17
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.