Skip to content

Commit

Permalink
Revert "Implement rate limiter based on atomic int64 operations (#85)" (
Browse files Browse the repository at this point in the history
#91)

This reverts commit f04376c.
  • Loading branch information
rabbbit committed Jun 9, 2022
1 parent bd00da1 commit 8b3fccf
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 109 deletions.
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

0 comments on commit 8b3fccf

Please sign in to comment.