GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf: S3 concurrency semaphore and lock-free flush uploads by klaudworks · Pull Request #111 · KafScale/platform

Conversation

@klaudworks

@klaudworks klaudworks commented Feb 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Status quo

  1. Every PartitionLog issues S3 calls independently with no shared concurrency limit. The only bound is the SDK's default MaxConnsPerHost: 2048. Total concurrent S3 calls is effectively active_connections * partitions_per_request * 2 for writes, plus active_connections * ReadAheadSegments for prefetch reads.

  2. flushLocked holds l.mu for the entire flush cycle — buffer drain, segment build, S3 upload, and metadata commit. Every AppendBatch and Read on the same partition blocks during S3 upload.

Shortcomings and fixes

flushLocked blocks reads and writes.: flushLocked holds l.mu during S3 uploads, blocking AppendBatch and Read on the same partition until the upload completes. Fixed by splitting into prepareFlush (buffer drain + segment build, under l.mu) and uploadFlush (S3 I/O, no lock held). A flushing flag + sync.Cond serializes concurrent flushes on the same partition.

Unbounded concurrent S3 calls. Each partition issues S3 calls independently with no shared limit. Under load with many partitions, the broker can have hundreds of concurrent S3 requests with no backpressure. Fixed by adding a broker-wide semaphore (KAFSCALE_S3_CONCURRENCY, default 64) that caps concurrent S3 operations. Set to 0 to disable. For slower S3-compatible storages (Hetzner, IONOS, self-hosted MinIO), operators can lower this to match their backend's capacity.

Back-of-envelope for 64 as default concurrency: each 4MB segment on a 10 Gbps link takes 3.2ms to transfer + ~15ms S3 latency = 18.2ms total. One connection achieves 4MB / 18.2ms = ~1.76 Gbps effective throughput. To fill 10 Gbps: 10 / 1.76 = 6 concurrent requests. For 50 Gbps: 24. 64 covers even high-network instances with margin (and also leaves margin for lower s3 latency which would incr. required concurrency to saturate the network). The goal was basically to just set a default that will never throttle throughput while providing back pressure for edge cases.

Connection churn. The AWS SDK default keeps only 10 idle connections per host (MaxIdleConnsPerHost: 10). Under burst load, most connections are created fresh with a full TCP+TLS handshake. Fixed by setting MaxConnsPerHost and MaxIdleConnsPerHost to match the semaphore limit, keeping connections warm.

Prefetch goroutines competed equally with produce/consume for S3 capacity. Fixed by using non-blocking TryAcquire — prefetch is skipped when all tokens are taken. Also narrowed l.mu to just the segment list read so prefetch I/O doesn't block appends.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
klaudworks added 2 commits February 25, 2026 20:11
@klaudworks
perf: add S3 concurrency semaphore and release mutex during flush upl…
6a2154f
…oads

Introduce a broker-wide semaphore (KAFSCALE_S3_CONCURRENCY, default 64)
that caps concurrent S3 operations across all partitions. Align the HTTP
transport connection pool with the same limit.

Split flushLocked into prepareFlush (under lock) and uploadFlush (lock-free)
so that AppendBatch and Read callers are no longer blocked behind S3 I/O.
Serialize concurrent flushes on the same partition via a flushing flag and
sync.Cond. Prefetch uses TryAcquire to avoid blocking critical-path I/O.
@klaudworks
chore: remove low-value comments that restate the code
c1f0dfb
@klaudworks
klaudworks marked this pull request as ready for review February 25, 2026 20:05
@novatechflow

novatechflow commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator

Thank you @klaudworks - please add the new switch into the /docs? We use a dedicated branch - gh-pages - for our docs rendering, operations (https://kafscale.io/operations/) would be a good candidate?

klaudworks reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@klaudworks

klaudworks commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator Author

@novatechflow Sure, I'll look into it later today and look for most fitting place e.g. operations.

novatechflow reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@klaudworks
docs: add KAFSCALE_S3_CONCURRENCY to broker env var index
e5d307b
@klaudworks

klaudworks commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator Author

@novatechflow added the docs

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

novatechflow
novatechflow approved these changes Feb 26, 2026
View reviewed changes

@novatechflow novatechflow left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you @klaudworks !

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

klaudworks reacted with heart emoji
All reactions
  • ❤️ 1 reaction
novatechflow
novatechflow approved these changes Feb 26, 2026
View reviewed changes
@novatechflow
novatechflow merged commit b1fc0da into KafScale:main Feb 26, 2026
4 checks passed

Uh oh!

There was an error while loading. Please reload this page.

kamir pushed a commit to kamir/kafscale that referenced this pull request Mar 5, 2026
@klaudworks @kamir
perf: S3 concurrency semaphore and lock-free flush uploads (KafScale#111
bb8c945
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@novatechflow novatechflow novatechflow approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@klaudworks @novatechflow
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.