Skip to content

fix: optimize spinlock with exponential backoff#5602

Open
vibe-sudo wants to merge 1 commit into
zeromicro:masterfrom
vibe-sudo:fix/spinlock-backoff-optimize
Open

fix: optimize spinlock with exponential backoff#5602
vibe-sudo wants to merge 1 commit into
zeromicro:masterfrom
vibe-sudo:fix/spinlock-backoff-optimize

Conversation

@vibe-sudo
Copy link
Copy Markdown

What type of PR is this?

  • Optimization

What this PR does:

  • Optimize the original spinlock with exponential backoff algorithm, referring to the implementation of panjf2000/ants spinlock
  • Reduce CPU usage under high concurrency
  • Improve performance by 4x~6x in high contention scenarios
  • Keep full API compatibility (no breaking changes)

Benchmark result

Before (old pure spinlock):
goos: windows
goarch: amd64
pkg: github.com/zeromicro/go-zero/core/syncx
cpu: AMD Ryzen 7 5700X 8-Core Processor
BenchmarkSpinLock
BenchmarkSpinLock-16 236873599 5.066 ns/op

After (optimized with exponential backoff):
goos: windows
goarch: amd64
pkg: github.com/zeromicro/go-zero/core/syncx
cpu: AMD Ryzen 7 5700X 8-Core Processor
BenchmarkSpinLock
BenchmarkSpinLock-16 273461516 4.388 ns/op

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant