Repository navigation
perf: stream large cache hits without pipe staging - #197
Merged
Merged
Conversation
Greptile SummaryThis PR replaces pipe-staged delivery of large whole-object cache hits with direct streaming through a lazy response writer.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "perf: classify incomplete cache streams ..." | Re-trigger Greptile |
Contributor
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
|
🎉 This PR is included in version 1.21.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Stream large whole-object cache hits directly to the response writer instead of staging them through
io.Pipe, a goroutine, and a second copy. A lazy writer commits cached headers andX-Cache: HITon the first non-empty write, so empty and pre-commit failures still fall back safely.After commitment, a cache stream failure still avoids appending an upstream response, but now records the request as an error so truncated transfers are visible in request metrics. Small-object, range, block, and miss paths remain unchanged.
Testing
make lint-cimake testgo test -race -run '^(TestServeFromCache_LargeObject|TestServeFromCache_LargeObjectUncommittedBeforeFirstByte|TestHandleGetObject_LargeEmptyCacheHitFallsBackBeforeHeaders|TestHandleGetObject_LargeCacheHitPostCommitErrorDoesNotFallBack)$' ./proxyThe benchmark covers warmed 128 KiB, 1 MiB, and 4 MiB embedded-cache hits through
handlers.Server.Workload:
warmed 128 KiB full-object embedded-cache HTTP GET through handlers.ServerB/opallocs/opWorkload:
warmed 1 MiB full-object embedded-cache HTTP GET through handlers.ServerB/opWorkload:
warmed 4 MiB full-object embedded-cache HTTP GET through handlers.ServerB/opGenerated by Perfloop. Measurements and checks.
Note
Medium Risk
Changes hot-path GET/cache-hit response commitment and error propagation for large objects; incorrect lazy-commit logic could break fallback or leave clients with truncated bodies, though new tests cover the main edge cases.
Overview
Large whole-object cache hits no longer go through
io.Pipe, a background goroutine, and an extra copy.serveFromCachestreams the cache body straight to the client via a newlazyCommitWriterthat writes cached headers andX-Cache: HITonly on the first non-empty chunk, so empty streams and failures before any body bytes still allow upstream fallback without sending cache-hit headers.If streaming fails after the response is committed, the handler no longer returns that error (avoiding a second upstream response appended to a partial body) but records the request as an error in metrics and logs a warning. Small-object buffering, range/block paths, and miss behavior are unchanged aside from comment tweaks on the 64KB threshold.
Adds
proxy/cache_hit_stream_test.gofor multi-chunk success, pre-commit failure, empty-body miss fallback, and post-commit failure/metrics behavior, plusBenchmarkHandlerWarmedEmbeddedCacheHitincmd/tagfor warmed 128 KiB–4 MiB embedded-cache GETs throughhandlers.Server.Reviewed by Cursor Bugbot for commit c48ec45. Bugbot is set up for automated code reviews on this repo. Configure here.