<s>
A	O
cache	B-Operating_System
stampede	I-Operating_System
is	O
a	O
type	O
of	O
cascading	O
failure	O
that	O
can	O
occur	O
when	O
massively	O
parallel	B-Operating_System
computing	I-Operating_System
systems	O
with	O
caching	B-General_Concept
mechanisms	O
come	O
under	O
very	O
high	O
load	O
.	O
</s>
<s>
This	O
behaviour	O
is	O
sometimes	O
also	O
called	O
dog-piling	B-Operating_System
.	O
</s>
<s>
To	O
understand	O
how	O
cache	B-Operating_System
stampedes	I-Operating_System
occur	O
,	O
consider	O
a	O
web	B-Application
server	I-Application
that	O
uses	O
memcached	B-Application
to	O
cache	B-General_Concept
rendered	O
pages	O
for	O
some	O
period	O
of	O
time	O
,	O
to	O
ease	O
system	O
load	O
.	O
</s>
<s>
Under	O
low	O
load	O
,	O
cache	B-General_Concept
misses	O
result	O
in	O
a	O
single	O
recalculation	O
of	O
the	O
rendering	O
operation	O
.	O
</s>
<s>
The	O
system	O
will	O
continue	O
as	O
before	O
,	O
with	O
average	O
load	O
being	O
kept	O
very	O
low	O
because	O
of	O
the	O
high	O
cache	B-General_Concept
hit	O
rate	O
.	O
</s>
<s>
However	O
,	O
under	O
very	O
heavy	O
load	O
,	O
when	O
the	O
cached	O
version	O
of	O
that	O
page	O
expires	O
,	O
there	O
may	O
be	O
sufficient	O
concurrency	B-Operating_System
in	O
the	O
server	O
farm	O
that	O
multiple	O
threads	O
of	O
execution	O
will	O
all	O
attempt	O
to	O
render	O
the	O
content	O
of	O
that	O
page	O
simultaneously	O
.	O
</s>
<s>
Systematically	O
,	O
none	O
of	O
the	O
concurrent	B-Operating_System
servers	O
know	O
that	O
the	O
others	O
are	O
doing	O
the	O
same	O
rendering	O
at	O
the	O
same	O
time	O
.	O
</s>
<s>
Thus	O
,	O
cache	B-Operating_System
stampede	I-Operating_System
reduces	O
the	O
cache	B-General_Concept
hit	O
rate	O
to	O
zero	O
and	O
keeps	O
the	O
system	O
continuously	O
in	O
congestion	O
collapse	O
as	O
it	O
attempts	O
to	O
regenerate	O
the	O
resource	O
for	O
as	O
long	O
as	O
the	O
load	O
remains	O
very	O
heavy	O
.	O
</s>
<s>
Then	O
,	O
when	O
the	O
cached	O
page	O
expires	O
,	O
we	O
have	O
30	O
processes	O
simultaneously	O
recomputing	O
the	O
rendering	O
of	O
the	O
page	O
and	O
updating	O
the	O
cache	B-General_Concept
with	O
the	O
rendered	O
page	O
.	O
</s>
<s>
Below	O
is	O
a	O
typical	O
cache	B-General_Concept
usage	O
pattern	O
for	O
an	O
item	O
that	O
needs	O
to	O
be	O
updated	O
every	O
units	O
of	O
time	O
:	O
</s>
<s>
If	O
the	O
function	O
takes	O
a	O
long	O
time	O
and	O
the	O
key	O
is	O
accessed	O
frequently	O
,	O
many	O
processes	O
will	O
simultaneously	O
call	O
upon	O
expiration	O
of	O
the	O
cache	B-General_Concept
value	O
.	O
</s>
<s>
Several	O
approaches	O
have	O
been	O
proposed	O
to	O
mitigate	O
cache	B-Operating_System
stampedes	I-Operating_System
(	O
also	O
known	O
as	O
dogpile	O
prevention	O
)	O
.	O
</s>
<s>
To	O
prevent	O
multiple	O
simultaneous	O
recomputations	O
of	O
the	O
same	O
value	O
,	O
upon	O
a	O
cache	B-General_Concept
miss	O
a	O
process	O
will	O
attempt	O
to	O
acquire	O
the	O
lock	O
for	O
that	O
cache	B-General_Concept
key	O
and	O
recompute	O
it	O
only	O
if	O
it	O
acquires	O
it	O
.	O
</s>
<s>
This	O
solution	O
moves	O
the	O
recomputation	O
of	O
the	O
cache	B-General_Concept
value	O
from	O
the	O
processes	O
needing	O
it	O
to	O
an	O
external	O
process	O
.	O
</s>
<s>
In	O
addition	O
,	O
this	O
solution	O
requires	O
unnatural	O
code	O
separation/duplication	O
and	O
is	O
mostly	O
suited	O
for	O
static	O
cache	B-General_Concept
keys	O
(	O
i.e.	O
,	O
not	O
dynamically	O
generated	O
,	O
as	O
in	O
the	O
case	O
of	O
keys	O
indexed	O
by	O
an	O
id	O
)	O
.	O
</s>
<s>
With	O
this	O
approach	O
,	O
each	O
process	O
may	O
recompute	O
the	O
cache	B-General_Concept
value	O
before	O
its	O
expiration	O
by	O
making	O
an	O
independent	O
probabilistic	O
decision	O
,	O
where	O
the	O
probability	O
of	O
performing	O
the	O
early	O
recomputation	O
increases	O
as	O
we	O
get	O
closer	O
to	O
the	O
expiration	O
of	O
the	O
value	O
.	O
</s>
<s>
This	O
approach	O
is	O
simple	O
to	O
implement	O
and	O
effectively	O
reduces	O
cache	B-Operating_System
stampedes	I-Operating_System
by	O
automatically	O
favoring	O
early	O
recomputations	O
when	O
the	O
traffic	O
rate	O
increases	O
.	O
</s>
<s>
One	O
drawback	O
is	O
that	O
it	O
takes	O
more	O
memory	O
in	O
cache	B-General_Concept
as	O
we	O
need	O
to	O
bundle	O
the	O
value	O
delta	O
with	O
the	O
cache	B-General_Concept
item	O
-	O
when	O
the	O
caching	B-General_Concept
system	O
does	O
not	O
support	O
retrieval	O
of	O
the	O
key	O
expiration	O
time	O
,	O
we	O
also	O
need	O
to	O
store	O
the	O
(	O
that	O
is	O
,	O
)	O
in	O
the	O
bundle	O
.	O
</s>
