Opened 16 years ago

Closed 14 years ago

#6199 closed (wontfix)

Avoid cache stampedes

Reported by: Jeremy Dunck Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Keywords: performance scalability cache
Cc: jdunck@…, sw+django@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

From the patch:

+    Avoids cache stampeding by missing on *one* request prior to actual
+    expiration.  That single missed requestor then refills the cache prior to
+    real expiration.  All other requestors still get hits.
+    
+    Adapted from MintCache from gfranxman:
+    http://www.djangosnippets.org/snippets/155/

This is also similar to mnot's stale-while-revalidate:
http://www.mnot.net/blog/2007/12/12/stale

The cache wrapper works with any backend, but does have a 2% access overhead. Additionally, rather than storing exactly what is asked in the backend, additional bookkeeping data is stored in a tuple alongside the original object.

Attachments (1)

cache_avoid_stampede.diff (9.2 KB ) - added by Jeremy Dunck 16 years ago.
Implementation, test, docs included.

Download all attachments as: .zip

Change History (7)

by Jeremy Dunck, 16 years ago

Attachment: cache_avoid_stampede.diff added

Implementation, test, docs included.

comment:1 by Simon Greenhill <dev@…>, 16 years ago

Has patch: set
Triage Stage: UnreviewedDesign decision needed

comment:2 by krystal, 15 years ago

milestone: 1.1

FYI, there is an other snippets that do the same : http://www.djangosnippets.org/snippets/793/

IMHO, this change should really be merged in the core ; dog-piling is a common and dirty problem for everyone who have a few visitors and it's not adressed in django.

If the patch is not included, we should mention this effect on the Documentation page to help people know why their server crash under load :)

(I put the milestone to 1.1 so this patch get a "design decision", sorry if I shouldn't)

comment:3 by krystal, 15 years ago

Cc: sw+django@… added

comment:4 by Jeremy Dunck, 15 years ago

krystal, in fact this is an improved version of that snippet.

However, I would be surprised if this was included in core-- it can now be accomplished with a custom CACHE_BACKEND.

comment:5 by Russell Keith-Magee, 15 years ago

milestone: 1.1
Patch needs improvement: set
Triage Stage: Design decision neededAccepted

I can see that there is room for a dogpiling and other cache management strategies. However, as jdunck notes, this can now be acheived with a custom cache backend. This patch would need to be recast in those terms if it were to be integrated into trunk.

Regardless, this won't be happening for v1.1

comment:6 by Jeremy Dunck, 14 years ago

Resolution: wontfix
Status: newclosed

I'm wontfixing my own ticket; since CACHE_BACKEND allows extension, this doesn't belong in core.

I'll see about adding this to django-extensions.

Note: See TracTickets for help on using tickets.
Back to Top