Skip to content

Slice: Add prefetch deduplication and freelist - #12949

Merged
zwoop merged 2 commits into
apache:masterfrom
zwoop:SlicePrefetch
May 28, 2026
Merged

zwoop merged 2 commits into
apache:masterfrom
zwoop:SlicePrefetch

Conversation

@zwoop

@zwoop zwoop commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Track in-flight prefetches per remap instance using a mutex- protected set to prevent duplicate upstream requests. Recycle BgBlockFetch objects via a freelist under the same mutex. Fire the initial prefetch burst at header parse time so faster clients benefit sooner.

Co-Authored-By: Craig Taylor (who also did all the investigations"

Track in-flight prefetches per remap instance using a mutex-
protected set to prevent duplicate upstream requests. Recycle
BgBlockFetch objects via a freelist under the same mutex. Fire
the initial prefetch burst at header parse time so faster
clients benefit sooner.

Co-Authored-By: Craig Taylor (and research)
@zwoop zwoop added this to the 11.0.0 milestone Mar 8, 2026
@zwoop zwoop self-assigned this Mar 8, 2026
@zwoop zwoop added the slice label Mar 8, 2026
@zwoop
zwoop marked this pull request as draft March 8, 2026 17:28
@zwoop
zwoop requested a review from Copilot March 8, 2026 17:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the slice plugin’s background prefetching by deduplicating in-flight prefetch requests per remap Config instance and reusing BgBlockFetch objects via a mutex-protected freelist. It also triggers the initial prefetch burst earlier (at server header-parse time) to improve time-to-first-byte for fast clients.

Changes:

  • Add schedule_prefetch() helper and shift initial prefetch scheduling to server response header parse time.
  • Update BgBlockFetch::schedule() to accept a URL-derived key and deduplicate via Config-owned tracking.
  • Add Config prefetch state: mutex + active-key set + freelist, with cleanup in Config destructor.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
plugins/slice/util.h Exposes schedule_prefetch() helper.
plugins/slice/util.cc Implements schedule_prefetch() and uses it for sliding-window prefetching.
plugins/slice/server.cc Schedules initial prefetch burst once response headers are parsed.
plugins/slice/prefetch.h Extends BgBlockFetch with config/key state and updated schedule() signature.
plugins/slice/prefetch.cc Implements dedup + freelist release/cleanup and integrates them into bg fetch lifecycle.
plugins/slice/Config.h Adds prefetch dedup/freelist data structures and APIs.
plugins/slice/Config.cc Implements prefetchAcquire() and calls cleanup from Config destructor (plus UNITTEST stubs).

Comment thread plugins/slice/prefetch.cc
Comment thread plugins/slice/prefetch.cc
Comment thread plugins/slice/Config.cc
Comment thread plugins/slice/prefetch.h
Comment thread plugins/slice/util.cc Outdated
Guard prefetchCleanup() with m_prefetch_mutex to prevent
data race with concurrent prefetchRelease() calls. Add unit
tests for prefetchAcquire() dedup semantics. Add missing
#include <string_view> to prefetch.h. Null-guard the result
of TSUrlStringGet() in schedule_prefetch() before constructing
std::string_view.
@zwoop

zwoop commented Mar 8, 2026

Copy link
Copy Markdown
Contributor Author

Addressed Co-Pilot's concerns.

@ezelkow1

ezelkow1 commented Mar 9, 2026

Copy link
Copy Markdown
Member

[approve ci]

@bryancall
bryancall requested a review from traeak March 9, 2026 22:13
@zwoop
zwoop marked this pull request as ready for review April 7, 2026 21:53

@traeak traeak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are fine. They could use an autest to issue multiple in parallel requests but not necessary.

@zwoop
zwoop merged commit cfae05c into apache:master May 28, 2026
15 checks passed
@zwoop
zwoop deleted the SlicePrefetch branch May 28, 2026 16:34
@github-project-automation github-project-automation Bot moved this to For v10.2.0 in ATS v10.2.x Jun 16, 2026
@cmcfarlen cmcfarlen moved this from For v10.2.0 to Picked v10.2.0 in ATS v10.2.x Jun 16, 2026
@cmcfarlen cmcfarlen modified the milestones: 11.0.0, 10.2.0 Jun 16, 2026
@cmcfarlen

Copy link
Copy Markdown
Contributor

Cherry-picked to 10.2.x

cmcfarlen pushed a commit that referenced this pull request Jun 16, 2026
* Slice: Add prefetch deduplication and freelist

Track in-flight prefetches per remap instance using a mutex-
protected set to prevent duplicate upstream requests. Recycle
BgBlockFetch objects via a freelist under the same mutex. Fire
the initial prefetch burst at header parse time so faster
clients benefit sooner.

Co-Authored-By: Craig Taylor (and research)

* Address Copilot review comments

Guard prefetchCleanup() with m_prefetch_mutex to prevent
data race with concurrent prefetchRelease() calls. Add unit
tests for prefetchAcquire() dedup semantics. Add missing
#include <string_view> to prefetch.h. Null-guard the result
of TSUrlStringGet() in schedule_prefetch() before constructing
std::string_view.

(cherry picked from commit cfae05c)
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Jul 29, 2026
* Slice: Add prefetch deduplication and freelist

Track in-flight prefetches per remap instance using a mutex-
protected set to prevent duplicate upstream requests. Recycle
BgBlockFetch objects via a freelist under the same mutex. Fire
the initial prefetch burst at header parse time so faster
clients benefit sooner.

Co-Authored-By: Craig Taylor (and research)

* Address Copilot review comments

Guard prefetchCleanup() with m_prefetch_mutex to prevent
data race with concurrent prefetchRelease() calls. Add unit
tests for prefetchAcquire() dedup semantics. Add missing
#include <string_view> to prefetch.h. Null-guard the result
of TSUrlStringGet() in schedule_prefetch() before constructing
std::string_view.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Picked v10.2.0

Development

Successfully merging this pull request may close these issues.

5 participants