From 37bc8b1040825f9a9ed57e0447e04a4aac07b362 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 6 Jul 2017 12:43:47 +0200 Subject: [PATCH] mxqd: Enforce minimum job runtime of 30 seconds Throttle througput for junk jobs. We don't want to busy spin in the daemon and hammer the database if user submits several jobs which immediately die or finish. --- mxqd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mxqd.c b/mxqd.c index 7d188810..8d98ad09 100644 --- a/mxqd.c +++ b/mxqd.c @@ -1081,6 +1081,13 @@ int reaper_process(struct mxq_server *server,struct mxq_group_list *glist, struc } gettimeofday(&now, NULL); timersub(&now, &job->stats_starttime, &realtime); + + if (realtime.tv_sec<30) { + int wait=30-realtime.tv_sec; + mx_log_warning("user process finished to fast (%ld seconds) : delaying termination for %d seconds",realtime.tv_sec,wait); + sleep(wait); + } + res = getrusage(RUSAGE_CHILDREN, &rusage); if (res < 0) { mx_log_err("reaper: getrusage: %m");