From owner-freebsd-bugs@FreeBSD.ORG Mon May 10 08:30:18 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A628C16A4CE for ; Mon, 10 May 2004 08:30:18 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id EF13143D1D for ; Mon, 10 May 2004 08:30:17 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i4AFUHFZ077353 for ; Mon, 10 May 2004 08:30:17 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i4AFUHRe077323; Mon, 10 May 2004 08:30:17 -0700 (PDT) (envelope-from gnats) Resent-Date: Mon, 10 May 2004 08:30:17 -0700 (PDT) Resent-Message-Id: <200405101530.i4AFUHRe077323@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dmitry Morozovsky Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C640016A4CF for ; Mon, 10 May 2004 08:20:19 -0700 (PDT) Received: from woozle.rinet.ru (woozle.rinet.ru [195.54.192.68]) by mx1.FreeBSD.org (Postfix) with ESMTP id 979F543D31 for ; Mon, 10 May 2004 08:20:18 -0700 (PDT) (envelope-from marck@woozle.rinet.ru) Received: from woozle.rinet.ru (localhost [127.0.0.1]) by woozle.rinet.ru (8.12.11/8.12.11) with ESMTP id i4AFKHnO063340 for ; Mon, 10 May 2004 19:20:17 +0400 (MSD) (envelope-from marck@woozle.rinet.ru) Received: (from marck@localhost) by woozle.rinet.ru (8.12.11/8.12.11/Submit) id i4AFKHhu063339; Mon, 10 May 2004 19:20:17 +0400 (MSD) (envelope-from marck) Message-Id: <200405101520.i4AFKHhu063339@woozle.rinet.ru> Date: Mon, 10 May 2004 19:20:17 +0400 (MSD) From: Dmitry Morozovsky To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/66474: [patch] add jitter to cron(8) to smooth load spikes X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Dmitry Morozovsky List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 May 2004 15:30:18 -0000 >Number: 66474 >Category: bin >Synopsis: [patch] add jitter to cron(8) to smooth load spikes >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon May 10 08:30:17 PDT 2004 >Closed-Date: >Last-Modified: >Originator: Dmitry Morozovsky >Release: FreeBSD 4-STABLE i386 >Organization: Cronyx Plus LLC (RiNet ISP) >Environment: System: FreeBSD 4-STABLE >Description: An a system with many users there are load spikes at the beginning of any minute when cron(8) executes jobs. This problem is addressed with the following patch (idea and first implementation by sply, cv-c -at- fluid -dot- ru). >How-To-Repeat: >Fix: Index: cron.8 =================================================================== RCS file: /home/ncvs/src/usr.sbin/cron/cron/cron.8,v retrieving revision 1.7.2.9 diff -u -r1.7.2.9 cron.8 --- cron.8 11 Mar 2003 21:13:48 -0000 1.7.2.9 +++ cron.8 10 May 2004 15:05:13 -0000 @@ -25,6 +25,7 @@ .Nd daemon to execute scheduled commands (Vixie Cron) .Sh SYNOPSIS .Nm +.Op Fl j Ar jitter .Op Fl s .Op Fl o .Op Fl x Ar debugflag Ns Op , Ns Ar ... @@ -78,6 +79,13 @@ .Pp Available options: .Bl -tag -width indent +.It Fl j Ar jitter +Enable exec jitter: before executing commands, +.Nm +will sleep random time (in seconds) between 0 and +.Ar jitter . +.Ar jitter +must be between 0 (disabled) and 60 (one minute). .It Fl s Enable special handling of situations when the GMT offset of the local timezone changes, such as the switches between the standard time and Index: cron.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/cron/cron/cron.c,v retrieving revision 1.9.2.2 diff -u -r1.9.2.2 cron.c --- cron.c 28 May 2001 23:37:26 -0000 1.9.2.2 +++ cron.c 10 May 2004 15:05:13 -0000 @@ -51,7 +51,7 @@ usage() { char **dflags; - fprintf(stderr, "usage: cron [-s] [-o] [-x debugflag[,...]]\n"); + fprintf(stderr, "usage: cron [-j jitter] [-s] [-o] [-x debugflag[,...]]\n"); fprintf(stderr, "\ndebugflags: "); for(dflags = DebugFlagNames; *dflags; dflags++) { @@ -415,8 +415,13 @@ { int argch; - while ((argch = getopt(argc, argv, "osx:")) != -1) { + while ((argch = getopt(argc, argv, "j:osx:")) != -1) { switch (argch) { + case 'j': + if ((Jitter = atoi(optarg)) < 0 || + Jitter > 60) + errx(1, "bad -j value: %s", optarg); + break; case 'o': dst_enabled = 0; break; Index: cron.h =================================================================== RCS file: /home/ncvs/src/usr.sbin/cron/cron/cron.h,v retrieving revision 1.9.2.3 diff -u -r1.9.2.3 cron.h --- cron.h 28 May 2001 23:37:26 -0000 1.9.2.3 +++ cron.h 10 May 2004 15:05:13 -0000 @@ -268,7 +268,8 @@ }; char *ProgramName; -int LineNumber; +int LineNumber, + Jitter; time_t TargetTime; # if DEBUGGING @@ -283,7 +284,8 @@ *MonthNames[], *DowNames[], *ProgramName; -extern int LineNumber; +extern int LineNumber, + Jitter; extern time_t TargetTime; # if DEBUGGING extern int DebugFlags; Index: do_command.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/cron/cron/do_command.c,v retrieving revision 1.15.2.6 diff -u -r1.15.2.6 do_command.c --- do_command.c 22 Jun 2003 18:49:39 -0000 1.15.2.6 +++ do_command.c 10 May 2004 15:05:13 -0000 @@ -251,6 +251,10 @@ #endif chdir(env_get("HOME", e->envp)); + if (Jitter != 0) { + srandom(getpid()); + sleep(random() % Jitter); + } /* exec the command. */ { >Release-Note: >Audit-Trail: >Unformatted: