groupcache: populate hotCache based on reported peer QPS#179
Open
mertovun wants to merge 2 commits into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Peek looks up a key's value without updating its recency, unlike Get which moves the entry to the front of the LRU list. This is useful for inspecting an entry (for example, to read per-key statistics) without affecting eviction order.
Previously, getFromPeer mirrored a remotely fetched value into the hotCache on a fixed 10% of fetches, chosen at random. This was a placeholder (noted in a TODO) and is a poor signal: it pollutes the hotCache with one-off keys while taking ~10 round trips on average to mirror a genuinely hot key, defeating the purpose of the hotCache. Use the value's owner as the authority on hotness instead. The owner tracks a per-key request rate using an exponentially weighted moving average and reports it in the GetResponse.MinuteQps field (which the wire format already carried but nobody populated). A non-owning peer mirrors a key into its hotCache only once the owner reports a rate at or above hotQPS. The per-key rate state lives inside the mainCache entry, so it is bounded by cache residency and cleaned up by ordinary eviction, with no separate accounting to evict. This replaces the test-only *rand.Rand hook (added in golang#175) with an injectable clock, which TestPeers and the new stats tests use to drive QPS deterministically.
Author
|
I signed it! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getFromPeercurrently mirrors a remotely fetched value into thehotCacheon a fixed 10% of fetches, chosen at random. This was a placeholder — the code carried aTODO(bradfitz): use res.MinuteQps or something smart— and it is a poor hotness signal:hotCachewith one-off keys, spending a budget that is deliberately capped at ~1/8 of the cache; andhotCacheexists to shed.This change makes the value's owner the authority on hotness, which is the only process that can actually observe global demand for a key it owns.
How
keyStats, half-life of one minute) and reports it in theGetResponse.MinuteQpsfield — which the wire format already carried but nobody populated.hotCacheonly once the owner reports a rate at or abovehotQPS.mainCacheentry, so it is bounded by cache residency and cleaned up by ordinary eviction; there is no separate map to grow or evict.lru.Peek(first commit) lets the rate be read/updated without disturbing LRU recency.The test-only
*rand.Randhook (added in #175) is replaced with an injectable clock, whichTestPeersand the newstatstests use to drive QPS deterministically.TestPeersnow exercises the real path: cold peers cause no mirroring, and peers reportinghotQPScause peer-owned keys to be mirrored and subsequently served from thehotCachewith zero peer hits.Compatibility
No wire-format change;
MinuteQpsalready exists inGetResponse. A peer running older code reports0and simply never triggers mirroring, so the change is safe in a mixed-version fleet.Tests
go build ./...,go vet ./..., andgo test -race ./...all pass.I'm happy to sign the Google CLA if the CLA bot flags this.
🤖 Generated with Claude Code