Skip to content

[CELEBORN-2277] Replace synchronized in Flusher.getWorkerIndex with AtomicInteger#3621

Open
cxzl25 wants to merge 2 commits intoapache:mainfrom
cxzl25:CELEBORN-2277
Open

[CELEBORN-2277] Replace synchronized in Flusher.getWorkerIndex with AtomicInteger#3621
cxzl25 wants to merge 2 commits intoapache:mainfrom
cxzl25:CELEBORN-2277

Conversation

@cxzl25
Copy link
Contributor

@cxzl25 cxzl25 commented Mar 9, 2026

What changes were proposed in this pull request?

Replace the synchronized block in getWorkerIndex with an AtomicInteger.updateAndGet call using a CAS-based atomic operation.

Why are the changes needed?

The synchronized keyword locks the entire object and causes thread contention under high concurrency. Using AtomicInteger reduces lock scope to a single variable and avoids blocking overhead for this lightweight index increment operation.

Does this PR resolve a correctness bug?

No

Does this PR introduce any user-facing change?

No

How was this patch tested?

GHA

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

@SteNicholas
Copy link
Member

@cxzl25, please update the description of pull request.

Copy link

Copilot AI left a comment

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 updates the worker-side storage Flusher to reduce lock contention by replacing a synchronized round-robin worker index increment with an AtomicInteger.updateAndGet CAS-based increment.

Changes:

  • Replaced nextWorkerIndex from a mutable Int guarded by synchronized to an AtomicInteger.
  • Updated getWorkerIndex to compute the next index via AtomicInteger.updateAndGet(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants