On Sat, May 9, 2009 at 9:43 AM, Dossy Shiobara <[email protected]> wrote: > Ah, the stampeding herd cold start design problem ... > > The simplest solution is to add some jitter - i.e., don't expire things > exactly after 3600 seconds. Set the expiration to be X +/- N, where X is > your lifetime and N is the jitter which might be small like 10 or large like > 300, computed per object usually at the time it's cached. > > Over time, given a reasonable PRNG, you should have sufficient drift that > cache expiration will remain random but on a cold start you won't have all > your hot objects expiring at exactly the same time every X period.
Ah, something we agree on! Never underestimate the value of jitter. I have used exactly this technique on many projects and it works amazingly well. Just to be pedantic: The expiration should be "X +/- rand(n, N)" Where "n" is probably 0, but is some lower bound to the jitter, and less than "N" which is probably non-zero and is the upper bound to the jitter. As time goes to infinity, statistically the objects will expire on average every X seconds. You can also play with "startup jitter" where all the objects are not created at time 0 when the switch is flipped, but randomly over a period of time. This may or may not apply depending on your situation. I'm sure you guys there have thought about this, but it can be useful for a lot of things, so maybe other devs on the list will glean something. -Chad
