I shouldn't say that I implement randomness since that isn't optimal: the
reason I picked IP address was that the general use is to avoid everything
running at once, by using a modulo of the IP address (and optimal spreading)
it meant that jobs on sequentially numbered systems would definitely not run
at the same time.  The algorithm I took was to invert the significance of
the bits in the IP address:

xxx.xxx.xxx.1 => 1/2
xxx.xxx.xxx.2 => 1/4
xxx.xxx.xxx.3 => 3/4
xxx.xxx.xxx.4 => 1/8
etc.

(In reality it takes the whole IPv4 or IPv6 address and not just the least
significant part, the xxx'es simplify showing though)

You then take these and multiply them by range possible for a crontab field
(0-59 for seconds, minutes; 0-23 for hours, 1-28 for day of month, 0-6 for
day of week).  This lets you write something like:

R * * * * /usr/local/bin/foo

to run a job at a random minute that is different for every 60 sequential
machines.  Very handy for server farms or lots of virtual machines.

Reply via email to