Skip to content

perf(proxy): avoid cache populate completion wait - #148

Merged
ovaistariq merged 2 commits into
tigrisdata:mainfrom
perfloop-oss:perfloop-pr-open-dn2ssnb9er
Aug 11, 2026
Merged

ovaistariq merged 2 commits into
tigrisdata:mainfrom
perfloop-oss:perfloop-pr-open-dn2ssnb9er

Conversation

@perfloop-agent

@perfloop-agent perfloop-agent commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Return a cacheable full-GET fetcher after upstream EOF instead of blocking on detached cache population.
  • Let broadcaster completion close cache listeners while preserving immediate cache-write error observation and late-error logging.
  • Prefer ready broadcast headers over concurrent request cancellation so a completed response can still publish its cache entry, with regression coverage for the cancellation boundary, cache hit, late error, and slot release.

Behavior

Cache publication remains asynchronous and subject to the existing admission and write-timeout limits. A follow-up request can still be a miss until the detached populate finishes.

Testing

  • make lint-ci
  • make test-proxy
  • go test -race -timeout 120s ./proxy/...
  • go vet ./proxy/...

Workload: cacheable-full-get-miss-handler-completion

Metric Before After Change
ns/op 101216495 572750 99.4% lower
All 4 declared correctness checks passed.

Authored and verified by Perfloop: every claim above was co-measured on both trees and independently re-verified before submission — the full record is public: case_mtzbwvz133. Replies from this account are human-approved, and a human operator is accountable for this contribution.


Note

Medium Risk
Changes timing and cancellation behavior on the hot GET/cache-populate path; correctness relies on detached listeners and late-error handling, with substantial new tests but real production concurrency edge cases.

Overview
Cacheable full-GET misses now finish the upstream streaming path as soon as the body is read, instead of waiting up to 100ms (or longer) for detached cache population.

In streamFromUpstream, the handler no longer blocks on cacheErrCh; it logs an immediate cache-write error if one is already available, otherwise spawns a goroutine to log late failures. fetchAndBroadcast can call broadcaster.Complete after upstream EOF so listeners close promptly while populate continues in the background.

Listener.WaitForHeaders re-checks headerCh when ctx is already canceled, so a cache listener scheduled after the HTTP handler returns still sees ready headers and can publish the entry instead of losing the race to cancellation.

Regression coverage adds benchmarks and tests for handler completion timing, a follow-up cache hit on a separate connection, the header-vs-cancel boundary, late cache-write logging, and populate slot release.

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

@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR removes the cache-population completion delay from cacheable full GET responses while preserving asynchronous publication and late-error reporting.

  • Makes ready broadcast headers take precedence over simultaneous request cancellation.
  • Observes cache-write completion asynchronously after the upstream stream reaches EOF.
  • Adds regression tests for cache publication, cancellation timing, late failures, and slot release, plus a handler-completion benchmark.

Confidence Score: 5/5

The PR appears safe to merge; no concrete correctness, resource-lifecycle, or security failure remains.

Cache population remains detached under a bounded context, its result channel and populate slot are cleaned up on all examined paths, and both immediate and late write failures remain observable.

Important Files Changed

Filename Overview
proxy/get_object.go Replaces the ineffective bounded cache-completion wait with nonblocking result observation and a bounded-lifetime late-error observer.
proxy/broadcast/broadcaster.go Makes already-published headers win when header readiness and context cancellation coincide, allowing detached cache listeners to proceed.
proxy/cache_populate_completion_test.go Covers asynchronous publication, cache hits, cancellation at header readiness, late write-error logging, and populate-slot release.
proxy/broadcast/broadcaster_test.go Adds focused regression coverage for simultaneous header readiness and context cancellation.
proxy/cache_populate_benchmark_test.go Benchmarks client-visible handler completion separately from eventual asynchronous cache publication.

Reviews (1): Last reviewed commit: "perf(proxy): avoid cache populate comple..." | Re-trigger Greptile

@perfloop-agent

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@ovaistariq

Copy link
Copy Markdown
Contributor

Thanks for the contribution. This looks good.

@ovaistariq
ovaistariq merged commit 96438ad into tigrisdata:main Aug 11, 2026
7 of 12 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 11, 2026
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.17.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants