SplayTime testing
From Cfwiki
I was curious about how exactly cfengine figures out how long to wait for SplayTime. The docs say:
Every machine will go to sleep for a different length of time, which is no longer than the time you specify in minutes. A hashing algorithm, based on the fully qualified name of the host, is used to compute a unique time for hosts. The shorter the interval, the more clustered the hosts will be. Tutorial Link
Note that if you use update.conf, there is only one SplayTime value for the whole execution run -- it won't splay based on update.conf and then splay again based on your main cfagent.conf's SplayTime value.
Here's a little program I wrote to exercise what a particular host's SplayTime will be based on the algorithm.
#include <stdio.h>
#include <readline/readline.h>
#define CF_MACROALPHABET 61 /* a-z, A-Z plus a bit */
#define CF_HASHTABLESIZE 4969 /* prime number */
int main()
{ int time, hash, done;
char *temp, *prompt;
time = 5; /* equivalent to SplayTime = ( 5 ) */
printf("Enter hostnames at the prompt. 'quit' quits.\n");
done = 0;
while(!done)
{
prompt = "hostname> ";
temp = readline(prompt);
if (!temp)
exit (1);
if (strcmp (temp, "quit") == 0)
done = 1;
hash = Hash(temp);
printf("My hash was %d and my time is %d\n", hash, (int)(time*60*hash/CF_HASHTABLESIZE));
}
}
int Hash(char *name)
{ int i, slot = 0;
for (i = 0; name[i] != '\0'; i++)
{
slot = (CF_MACROALPHABET * slot + name[i]) % CF_HASHTABLESIZE;
}
return slot;
}
