← Back to Pull requests

Cap pooled bulk buffer sizes to reduce memory retention #8396

Open
unknown opened this pull request with 220 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 30, 2026 13:48 UTC
Author

What is the problem this PR solves?

The bulk engine reuses pooled buffers for individual requests and batched Elasticsearch flushes with no capacity limit. After a large request or batch grows a buffer, the pool keeps that oversized allocation across garbage collection cycles and increases memory usage under load.

This change is extracted from https://github.com/elastic/fleet-server/pull/8372 which contains the scale-test results and regression checks.

How does this PR solve the problem?

When a buffer returns to its pool, the bulk engine discards flush buffers larger than 1 MiB and releases request buffers larger than 64 KiB so the garbage collector can reclaim them. Buffers at or below those limits remain in the pools for reuse.

How to test this PR locally

Run the affected unit tests:

go test -race -count=1 -run '^(TestFlushBufPoolCap|TestBlkPoolCap|TestCancelCtx|TestCancelCtxChildBulker|TestMSearch|TestMSearchFlushAfter|TestDispatchAbortQueueFreesBlk|TestDispatchAbortResponseReachesSecondSelect|TestDrainAndFreeAbortedBlkResponse|TestDispatchSuccess|TestMultiWriteOptionsReachElasticsearch)$' ./internal/pkg/bulk/

Design Checklist

  • I have ensured my design is stateless and will work when multiple fleet-server instances are behind a load balancer.

  • I have or intend to scale test my changes, ensuring it will work reliably with 100K+ agents connected.

  • I have included fail safe mechanisms to limit the load on fleet-server: rate limiting, circuit breakers, caching, load shedding, etc.
  • Checklist

  • I have commented my code, particularly in hard-to-understand areas

  • I have added tests that prove my fix is effective or that my feature works
  • Made with Cursor

    Diff: 220 lines (+165 / -55) across 2 files Reviewer: copilot-pull-request-reviewer[bot] Review duration: 1m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.37) × (1 − Review Confidence (0.26)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 220 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 36% · Reviewer familiarity: 35%
    26%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.323
    Real PR Conversation Timeline
    1 comments
    "Review active on #8396"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 26.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.8% (MEDIUM) · Higher = larger blast radius
    36.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 26.2% · Lower = rushed or shallow review
    26.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.1% · Safe to merge
    27.1%