Hacker News new | ask | show | jobs
by oarsinsync 2220 days ago
As a workaround, sounds like you need a deterministic pseudo-random number generator.

Find a value that is unique to each server (e.g. the UUID of the / partition?) to seed your PRNG, and then generate the first pseudo-random number. If you do it right, it will always be the same number.

Modulo this number against the number of (seconds|minutes|hours) of random delay you want applied, and apply a sleep timer to the start of the job based on that result.

It's dirty, but it ensures

* each server gets its own random interval from the start time

* that random interval never changes

* the server runs the job on a regular schedule

There are probably better ways of doing this, but this is the first thing I could think of that doesn't require any crazy libraries and can be done using standard linux utils that are on all machines.

I'd love to hear any better ways that people have!

1 comments

> Find a value that is unique to each server (e.g. the UUID of the / partition?) ...

FWIW, that's pretty much what /etc/machine-id is for.