Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "New atomic-based implementation squeezed into int64" #91

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 0 additions & 90 deletions limiter_atomic_int64.go

This file was deleted.

2 changes: 1 addition & 1 deletion ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type config struct {

// New returns a Limiter that will limit to the given RPS.
func New(rate int, opts ...Option) Limiter {
return newAtomicInt64Based(rate, opts...)
return newAtomicBased(rate, opts...)
}

// buildConfig combines defaults with options.
Expand Down
9 changes: 3 additions & 6 deletions ratelimit_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ func BenchmarkRateLimiter(b *testing.B) {
for _, procs := range []int{1, 4, 8, 16} {
runtime.GOMAXPROCS(procs)
for name, limiter := range map[string]Limiter{
"atomic": newAtomicBased(b.N * 1000000000000),
"atomic_int64": New(b.N * 1000000000000),
"mutex": newMutexBased(b.N * 1000000000000),
"atomic": New(b.N * 10000000),
"mutex": newMutexBased(b.N * 10000000),
} {
for ng := 1; ng < 16; ng++ {
runner(b, name, procs, ng, limiter, count)
Expand Down Expand Up @@ -48,9 +47,7 @@ func BenchmarkRateLimiter(b *testing.B) {
}

func runner(b *testing.B, name string, procs int, ng int, limiter Limiter, count *atomic.Int64) bool {
return b.Run(fmt.Sprintf("type:%s;max_procs:%d;goroutines:%d", name, procs, ng), func(b *testing.B) {
b.ReportAllocs()

return b.Run(fmt.Sprintf("type:%s-procs:%d-goroutines:%d", name, procs, ng), func(b *testing.B) {
var wg sync.WaitGroup
trigger := atomic.NewBool(true)
n := b.N
Expand Down
12 changes: 1 addition & 11 deletions ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,13 @@ func runTest(t *testing.T, fn func(testRunner)) {
return newAtomicBased(rate, opts...)
},
},
{
name: "atomic_int64",
constructor: func(rate int, opts ...Option) Limiter {
return newAtomicInt64Based(rate, opts...)
},
},
}

for _, tt := range impls {
t.Run(tt.name, func(t *testing.T) {
// Set a non-default time.Time since some limiters (int64 in particular) use
// the default value as "non-initialized" state.
clockMock := clock.NewMock()
clockMock.Set(time.Now())
r := runnerImpl{
t: t,
clock: clockMock,
clock: clock.NewMock(),
constructor: tt.constructor,
doneCh: make(chan struct{}),
}
Expand Down
1 change: 0 additions & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (

require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/storozhukBM/benchart v1.0.0
golang.org/x/exp/typeparams v0.0.0-20220328175248-053ad81199eb // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect
Expand Down