Skip to content

perf(auth): shard non-promoting auth cache lookups - #284

Open
perfloop[bot] wants to merge 1 commit into
mainfrom
perfloop-pr-open-wx61mgnaha
Open

perfloop[bot] wants to merge 1 commit into
mainfrom
perfloop-pr-open-wx61mgnaha

Conversation

@perfloop

@perfloop perfloop Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Every transparent Range cache hit validates the client's SigV4 request before reading the cache. This change parses auth once, looks up the exact learned signing key, performs the existing HMAC comparison, and checks the bucket grant without promoting the key or grant on a hit. The derived-key and authorization stores use bounded expirable-LRU shards with non-promoting Peek reads. Existing TTLs and synchronous 403 revocation remain in place; missing or expired entries still follow the upstream validation path.

The lookup change applies when TAG forwards transparently: default transparent mode and tiered mode with a Tigris endpoint. Signing mode keeps its credential-store path. The total limits remain 100K signing keys and 1M grants. Capacity is split across shards, so a full shard can evict while another has room; under a skewed key distribution this can cause an earlier upstream check, but never a local authorization on a miss.

The existing handlers/block_cache_certified_range_benchmark_test.go benchmark (BenchmarkHandleGetObjectCertifiedRange/local/blocks-2) exercises the production validator and auth stores on a routed block-range cache hit. Two local 2-second paired runs measured ns/op of 1,882,096 and 1,878,159 before versus 1,834,848 and 1,831,215 after; average ttfb-ns/op was 798,471 and 789,110 before versus 765,265 and 763,168 after. It is a sequential block-mode workload, not the high-fan-out whole-object Range workload.

The 64-worker replay harness at handlers/auth_cache_range_benchmark_test.go is temporary measurement support and is not included in this pull request. It prewarms learned keys and an embedded cache, then sends 64 concurrent valid-SigV4 requests with one identity per worker for 64KiB ranges from 100KiB whole-cached objects. The in-process router and production validator are measured for a fixed 400,000 requests per invocation, with 64 workers scheduled over four Go Ps; the fake upstream fails if a timed request misses. Setup verifies the exact range CRC, and each timed response checks 206/HIT, ETag, Content-Range, Content-Length, and byte count. The reported p99 is handler completion, not socket or client latency. A separate mutex profile was collected for the baseline and sharded lookup path; the profile files are local diagnostics and are not included in this pull request. Production request mix, frequency, and identity distribution remain unmeasured.

Workload Measure Metric Before median After median Paired change Outcome / requirement
64-worker per-identity prewarmed SigV4 64KiB Range GET requests/s 48211 56476 17.2% improvement passed
64-worker per-identity prewarmed SigV4 64KiB Range GET p99-ns/op 41689784 35368279 −15.3% non-regression passed; lower is better; required population loss ≤ 0.05 × |baseline median| p99-ns/op
64-worker per-identity prewarmed SigV4 64KiB Range GET time ns/op 20.74 µs 17.71 µs −14.7% non-regression passed; lower is better; required population loss ≤ 0.05 × |baseline median| ns

Each workload ran 9 paired runs.

Testing

make build and make lint-ci passed. The auth, proxy, and handler unit and race packages passed. Focused integration tests cover per-bucket grants, 403 revocation, write-only non-grants, presigned fallback, and multipart replay authorization.


Generated by Perfloop.


Note

Medium Risk
Changes the local SigV4 validation and authorization-cache hot path; sharded eviction can increase upstream checks under skew but should not grant cache access on misses.

Overview
Introduces a sharded, read-mostly TTL cache (readMostlyTTLTable) for transparent-proxy local auth: 64 expirable-LRU shards with Peek on reads so hot Range/cache hits do not promote entries or contend on a single LRU lock.

AuthzCache and DerivedKeyStore signing-key storage now use this table (same global caps: 1M grants, 100K keys); grants still use Store/Remove, TTLs and 403 revocation unchanged. validateLocally calls RequestValidator.Validate once (parse + exact key lookup + HMAC) instead of separate parse / HasKey / ValidateRequest, with the same missing-auth, parse-error, unknown-key, and signature-mismatch fallbacks to upstream; bucket checks use the validated access key.

Adds unit tests for non-promoting reads, bounded total capacity across shards, and concurrent read/write.

Reviewed by Cursor Bugbot for commit 6d558e5. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@greptile-apps

greptile-apps Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Summary

The PR splits signing keys and bucket grants across 64 bounded caches. Reads use Peek so hits do not change eviction order.

  • Transparent cache hits use sharded auth lookups that do not promote reads.

perfloop[bot] explicitly acknowledges that uneven shard use can cause earlier eviction and an extra upstream check.

Reviews (1) · Last reviewed commit: "perf(auth): shard cache-hit authenticati..." · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant