Skip to content

gcp-observability: Cache log filter decisions by RPC method - #13197

Closed
JoeCqupt wants to merge 3 commits into
grpc:masterfrom
JoeCqupt:feat/gcp-observability-log-filter-cache
Closed

JoeCqupt wants to merge 3 commits into
grpc:masterfrom
JoeCqupt:feat/gcp-observability-log-filter-cache

Conversation

@JoeCqupt

@JoeCqupt JoeCqupt commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cache log filter decisions by full RPC method name to avoid scanning the same rules on repeated calls. Client and server each have a separate FIFO cache capped at 1,024 entries.

Hits read from a ConcurrentHashMap without acquiring the cache lock. On a miss, the cache rechecks the key under the lock, evaluates the filters, and evicts the oldest entry if the cache is full. The first matching rule still determines whether to log and which payload limits to use.

Benchmark

Compared master (bbadd4ebd) with FIFO (aa8c2d125) using JMH 1.37 on an Apple M3 Pro with JDK 21. Each scenario used one shared ConfigFilterHelper and eight rules, with the last rule matching. Hit scenarios repeatedly queried one warmed method. In miss scenarios, each thread cycled through 4,096 distinct methods, forcing a miss and eviction on every FIFO lookup in steady state.

Workload Master (M lookups/s) FIFO (M lookups/s) FIFO vs. master
1 thread, cache hits 32.17 469.16 14.6× throughput
8 threads, cache hits 178.02 2,326.57 13.1× throughput
1 thread, continuous misses and evictions 38.01 17.69 53.5% lower
8 threads, continuous misses and evictions 213.51 8.21 96.2% lower

Repeated lookups benefit from caching, while sustained misses serialize rule matching and eviction on the shared cache lock. These measurements cover logRpcMethod() in isolation.

Reuse filter parameters for repeated calls to the same method.
Keep separate bounded caches for client and server rules so dynamic
method names cannot grow either cache without limit.
Use access order to evict the least recently used method. Synchronize
map access and keep filter matching outside the lock because concurrent
misses compute equivalent results.
@JoeCqupt JoeCqupt closed this Nov 21, 2026
Use ConcurrentHashMap for lookups so cache hits avoid the shared LRU
lock. Serialize misses and maintain insertion order to bound each
cache and reuse results from concurrent misses.
@JoeCqupt JoeCqupt reopened this Nov 21, 2026
@JoeCqupt JoeCqupt closed this Nov 21, 2026
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