Bug #80504
openrgw: Keystone credential cache expires all at once with no single-flight refresh, which hammers Keystone every 300s
0%
Description
Hi,
we run 34 S3 zones that authenticate against Keystone, and we keep getting
customer-visible errors whenever Keystone's rate limiter kicks in. After
digging into it with our own trace collector, the reason turns out to be the
shape of our requests rather than their number.
RGW caches a Keystone-validated S3 credential per daemon for 300 seconds. The
lifetime is hard-coded, and concurrent refreshes are not coalesced. So when the
entry expires, every in-flight request of that key inside that daemon misses the
cache in the same moment, and each one sends its own POST /v3/s3tokens. Nothing
waits for the first answer.
On a busy key that is 50 to 170 Keystone calls per daemon at once, every 300
seconds, from a single radosgw process. Keystone answers 429 to all but the
first few, RGW cannot validate the credential, and the request fails even
though the key is perfectly valid. #73088 covers that half of the problem, where
the 429 turns into a misleading 403 or 500.
The herd is inside one process, not spread over the cluster. In one burst we see
twelve failing requests with the same pid, in the same second, for the same
access key.
I should say clearly that the cache itself works fine. One zone did 12.5 million
cache hits against 7,758 refreshes in 24 hours. So this is not #73709, which I
opened last year and which was closed as can't-reproduce: there the cache looked
like it was not caching at all. Here it caches, the refreshes are just
synchronised and uncoalesced.
To give an idea of the scale: about 17,000 customer-visible errors a day across
the fleet. In our busiest zone the sustained Keystone call rate is 42 per
minute, which is well inside our operator's limit, while a single expiry burst
reaches around 600 calls in one minute. So it is the burst that breaks us, not
the average, and asking for a higher rate limit is an expensive workaround,
because it has to be sized for the peak.
Things that would help, the most useful first:
1. Single-flight refresh. The first thread that finds the entry expired does the
validation behind a per-key in-flight marker, and the others wait and reuse
the result. This is process-local, one mutex and one map, and needs no
coordination between daemons. It turns 50 to 170 calls per expiry into one,
so it removes I/O rather than adding it. (AI came up with this)
2. Some jitter on the lifetime, so a group of daemons stops refreshing in
lockstep. (My own idea)
3. Optionally serving the stale entry while a refresh is in flight. That would
remove the client-visible failure entirely, at the price of a bounded window
in which a revoked credential still works. Probably better as an option than
as the default. (My own idea)
Our configuration is rgw_keystone_token_cache_size 10000 and defaults
otherwise. Keystone is reached over HTTPS through a rate-limited nginx.
I can provide full debug 10 traces, the per-daemon refresh counts, or anything
else that helps. We have a collector running on the whole fleet that records
every 5xx with its trace, so the data is there.
Related: #73088 (the 429 becomes a misleading 403 or 500), #73709 (mine, closed
can't-reproduce, the cache does work and this is the expiry pattern instead),
#47859 (negative cache entries spreading the failure), #79931 (admin token
invalidation in EC2Engine).
Full disclosure: I used an AI assistant to analyse the traces and to write this
ticket. The numbers come from our own metrics and logs and I checked them.
Best wishes
Boris
CB Updated by Casey Bodley 3 months ago
- Related to Bug #67793: rgw: keystone authentication is not cached added
MH Updated by Matthew Heler 2 months ago
- Status changed from New to Fix Under Review
- Assignee set to Matthew Heler
- Pull request ID set to 71929