Opened 8 years ago

Closed 5 years ago

#6199 closed (wontfix)

Avoid cache stampedes

Reported by: jdunck Owned by: nobody
Component: Core (Cache system) Version: master
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: UI/UX:

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 jdunck 8 years ago.
Implementation, test, docs included.

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by jdunck

Implementation, test, docs included.

comment:1 Changed 7 years ago by Simon Greenhill <dev@…>

  • Has patch set
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 6 years ago by krystal

  • milestone set to 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 Changed 6 years ago by krystal

  • Cc sw+django@… added

comment:4 Changed 6 years ago by jdunck

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 Changed 6 years ago by russellm

  • milestone 1.1 deleted
  • Patch needs improvement set
  • Triage Stage changed from Design decision needed to Accepted

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 Changed 5 years ago by jdunck

  • Resolution set to wontfix
  • Status changed from new to closed

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