[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[monit-dev] control: consume less CPU time while waiting for a process t
From: |
Thomas Petazzoni |
Subject: |
[monit-dev] control: consume less CPU time while waiting for a process to start/stop |
Date: |
Wed, 11 Apr 2012 15:39:57 +0200 |
control: consume less CPU time while waiting for a process to start/stop
Monit uses the wait_start() and wait_stop() functions when waiting for
a given process to start and stop. In those functions, Monit polls the
state of those processes to find when they have started or stopped,
during a given timeout (by default EXEC_TIMEOUT, 30 seconds).
Unfortunately, during this period, Monit polls very aggressively: it
polls every 5 milliseconds to see if the process has started or
not. Since every 5 milliseconds Monit scans a quite important number
of files in /proc, it makes Monit consumes about 60-70% of the CPU
time on a faily low-end ARMv5 device (200 Mhz). And when the process
Monit tries to start effectively never starts (for some reason), then
Monit consumes 60-70% of the CPU time forever.
This value of 5 milliseconds being way to aggressive, we take a
different approach:
* During the first second, we poll every 200ms to see if the process
has started or has stopped
* During the rest of the timeout period, we poll every second
Signed-off-by: Thomas Petazzoni <address@hidden>
Index: b/src/control.c
===================================================================
--- a/src/control.c
+++ b/src/control.c
@@ -418,11 +418,18 @@
int isrunning = FALSE;
time_t timeout = time(NULL) + s->start->timeout;
int debug = Run.debug;
+ unsigned waiting_cycles = 0;
ASSERT(s);
while ((time(NULL) < timeout) && !Run.stopped) {
if ((isrunning = Util_isProcessRunning(s, TRUE)))
break;
- Time_usleep(5000);
+ /* Test if the process exists every 200ms during the
+ first second, and then every second */
+ if (waiting_cycles < 5)
+ Time_usleep(200 * 1000);
+ else
+ Time_usleep(1000 * 1000);
+ waiting_cycles++;
Run.debug = 0; // Turn off debug second time through to avoid
flooding the log with pid file does not exist. This poll stuff here _will_ be
refactored away
}
Run.debug = debug;
@@ -446,11 +453,18 @@
int isrunning = TRUE;
time_t timeout = time(NULL) + s->stop->timeout;
int debug = Run.debug;
+ unsigned waiting_cycles = 0;
ASSERT(s);
while ((time(NULL) < timeout) && !Run.stopped) {
if (! (isrunning = Util_isProcessRunning(s, TRUE)))
break;
- Time_usleep(5000);
+ /* Test if the process stopped every 200ms during the
+ first second, and then every second */
+ if (waiting_cycles < 5)
+ Time_usleep(200 * 1000);
+ else
+ Time_usleep(1000 * 1000);
+ waiting_cycles++;
Run.debug = 0; // Turn off debug second time through to avoid
flooding the log with pid file does not exist. This poll stuff here _will_ be
refactored away
}
Run.debug = debug;
--
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [monit-dev] control: consume less CPU time while waiting for a process to start/stop,
Thomas Petazzoni <=