in reply to Re^3: PerlMonks Caching (data)
in thread PerlMonks Caching
I didn't get that race condition anyway.
s/get/notice/
Different? Yes. Lacks the race? No.
Y: request arrives when Alice updates her node, N (having noticed a typo that makes her node appear extremely rude)
Y: delete N from memcached
X: request arrives when Bob downvotes looks at Alice's node, N
X: N found missing from memcached
X: read version 1 of N from memcached DB, N1
X: decrement 'reputation' field in N1, producing N2
X: flush N2 changes to DB (update ... rep=rep-1 ...)
X: re-read N from DB, yielding N2 again
X: the slowness of this web server matters at this point
Y: read version 1 of N from memcached DB, N1
Y: apply update to node text, producing N3 N2
Y: flush N3 N2 changes to DB (update ... doctext='...' ...)
Y: redirect to display node as response to update
Y: re-read N from DB, yeilding N4 N2 (includes both the text update and the reputation decrease)
Y: flush N to memcached, storing N4 N2
X: flush N to memcached, storing N2 N1 (Oops!)
In this scenario, Alice sees her update applied while nobody else does. If Alice refreshes, then her update mysteriously vanishes. With the 3-minute expiry, her update mysteriously appears again due to the cache timing out rather than when the next update is done.
Other than the race condition (which should just be fixed), I don't see the point in expiring the cache so frequently. Let the LRU do its job.
Your scheme seems more complicated (and less efficient) yet doesn't remove the race.
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: PerlMonks Caching (still racy)
by tinita (Parson) on Apr 21, 2010 at 18:54 UTC | |
|
Re^5: PerlMonks Caching (still racy)
by tinita (Parson) on Apr 21, 2010 at 19:43 UTC | |
by tye (Sage) on Apr 21, 2010 at 20:52 UTC | |
by tinita (Parson) on Apr 21, 2010 at 22:14 UTC | |
by tye (Sage) on Apr 22, 2010 at 04:17 UTC | |
by tinita (Parson) on Apr 22, 2010 at 08:54 UTC |