In crontabs man randomization is briefly touched upon, in terms of being “good” if set to 1 or above. It gives this example:
RANDOM=4
RANDOMTIME=8
What do 4 and 8 mean? Between 0 and 4 and 0 and 8, respectively? What is the unit?
In crontabs man randomization is briefly touched upon, in terms of being “good” if set to 1 or above. It gives this example:
RANDOM=4
RANDOMTIME=8
What do 4 and 8 mean? Between 0 and 4 and 0 and 8, respectively? What is the unit?
An integer.
random returns a random integer between 0 and the number it is called with, so in that example it would return an integer value between 0 and 4.
The manual (man 4 crontabs
) says they’re just seeds:
Randomization of jobs can be configured in the /etc/sysconfig/run-parts file. To enable randomization of jobs, set the RANDOMIZE parameter to 1 and set the RANDOM parameter to an integer which determines a random seed. Additionally, you may configure the RANDOMTIME parameter (again, by specifying an integer) to provide an additional level of randomization. Jobs are not randomized when the RANDOM and RANDOMTIME parameters are set to 0. Values in these two parameters must be set to 1 or larger to provide a good enough randomization.
A seed is simply a value you provide to the random number generator for it to use. In most (all?) implementations of random numbers, different seeds give different sets of random numbers.
So how exactly does randomization work? What exactly is randomized and by how much?
What is that returned value applied to, in terms of cron jobs?
Read the various man pages for cron. man cron, man crontab, man 5 crontab, man anacrontab
and more. it is explained with examples in those files, notably /etc/anacrontab uses a random delay.
Simply put, the random factor ensures that the jobs do not always run at exactly the same time of day with every time the job repeats.
In laymans terms, for a large server farm that is running the same task at the same time on every single server it could lead to overload of CPU, Storage, Network, etc. (similar to a DDOS attack). By randomizing the time those tasks start it spreads the load out over time yet still completes them.
All of that is read and understood but does not answer my question. It is clear that there is randomization. I do not question that. I question “by how much”.
This is executed by /usr/bin/run-parts
This is the piece that handles it …
if [ "$RANDOMIZE" != "" ]; then
let "rtime = $RANDOM"
if [ "$RANDOMTIME" != "" ]; then
let "rtime %= $RANDOMTIME"
else
let "rtime %= 300"
fi
sleep $rtime
fi
What's derived from this is the number of seconds that the process will be delayed before running.
From the bash man page for RANDOM
Each time this parameter is referenced, a random integer between
0 and 32767 is generated. The sequence of random numbers may be
initialized by assigning a value to RANDOM. If RANDOM is unset,
it loses its special properties, even if it is subsequently
reset.
Setting RANDOM=4, is the seed for the bash builtin $RANDOM
… or a starting point for the random sequence
You can see this by opening a terminal and doing:
RANDOM=4
echo $RANDOM
echo $RANDOM
RANDOM=4
echo $RANDOM
So rtime initially equals a number between 0 and 32767.
if RANDOMTIME is set the rtime value is divided by the RANDOMTIME, and the remainder is assigned to the rtime variable.
if RANDOMTIME is not set the rtime value is divided by 300, and the remainder is assigned to the rtime variable.
then it sleeps for the number of seconds rtime is set to and executes the command…
READ THE FILE
$ cat /etc/anacrontab
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
The random delay factor is ‘randomized’ to some value between 0 & 45 then added to the ‘delay in minutes’ value already entered for that job. Thus the value is added as some random number between 0 and the maximum value selected.
The value added is an integer value that is random between the limits of 0 and the RANDOM_DELAY factor entered.
If you come here voluntarily, you should drop the attitude and stop insulting members. Not everyone is capable of understanding everything. Not everyone spends their entire lifetime learning and researching Fedora. We have other tasks in life that take most of our time. And when we do not understand something, we come to ask the volunteer experts. But when these experts turn around and insult us in return, something is broken. Peace.
@computersavvy : I’m sure you know this already: your response here was not as excellent as it could be. Please be more excellent to folks on the forum. It’s better to not respond if you think a query does not merit your response than to respond in this way.
Noted and edited