18 ms·
Hear hear on said Old Wizened Graybeard habit. The amount of pain inflicted from twenty jobs all starting up at :00 (or even :30, :45, etc.) when they could eas
by mtsmith85 11y ago
Hear hear on said Old Wizened Graybeard habit. The amount of pain inflicted from twenty jobs all starting up at :00 (or even :30, :45, etc.) when they could easily run at :04 or :17 can be huge. Anecdotally I once "lost" a sandbox server to a ton of developer sandbox jobs starting at :00 and not completing before the next batch started.
- protomyth 11y agoFunny part to that, was on a project with multiple teams with multiple crontabs. Each team took that advice to heart for some jobs. Sadly, we had too many Hitchhiker fans and :42 became a bit too common.
- kijin 11y agoUse the following shell command to decide when to run cron jobs. echo $((RANDOM % 60)) It's not a CSPRNG, but good enough for this kind of load balancing!
- cperciva 11y agoOr schedule your cron job for :00, but add "sleep `jot -r 1 0 3600` &&" to the start of the command. (jot is a BSDism, but I assume you can do the same with GNU seq.)
- junkblocker 11y agosleep $[RANDOM/3600] works everywhere without requiring jot/seq etc. on BSD/Mac/Linux.
- cperciva 11y agos/\//%/ I assume?
- deleted 11y ago[deleted]
- junkblocker 11y agoOops s/\//\\%/ yeah. sleep $[RANDOM\%3600]
- hjnilsson 11y agoThat will be a number between 1 and 10 ($RANDOM only goes to 32767), sleep $[RANDOM/10] would be better. :) This might be platform dependent though, I can't find any standard RAND_MAX in bash so it's difficult to make this work everywhere.
- lloeki 11y agoThis works in (da)sh (tweak 2 and 65536 if needed): sleep $(( 0x$(xxd -l2 -p /dev/random) * 3600 / 65536 ))
- JoachimSchipper 11y agoDon't use that for hourly jobs, though - things are liable to break when you randomly run a command at, say, 12:59 and 13:00.
- cperciva 11y agoRight, I usually do that for my daily jobs.
- rlpb 11y agoThis is a pain when deciphering a series of events later, though, because you don't know when a particular job was supposed to start. I'd prefer the delay to be stable on a per-host basis.
- protomyth 11y agoWe just went with a single group text file with all the jobs and which ones could be spread out. Saves the programming and gives the sys admins / DBAs an idea what goes when.
- NDizzle 11y agoDon't run on :17 and :39. Those are mine. Thanks!