Skip to content

Commit df995ca

Browse files
committed
Increase burst for rate limiter
1 parent 8615288 commit df995ca

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

httpclient/api_client.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"golang.org/x/time/rate"
2323
)
2424

25+
const maxAllowedBurst = 10
26+
2527
type RequestVisitor func(*http.Request) error
2628

2729
type ClientConfig struct {
@@ -129,9 +131,18 @@ func NewApiClient(cfg ClientConfig) *ApiClient {
129131
rateLimit = rate.Inf
130132
cfg.RetryTimeout = 0
131133
}
134+
135+
burst := int(rateLimit)
136+
if burst > maxAllowedBurst {
137+
burst = maxAllowedBurst
138+
}
139+
if burst < 1 {
140+
burst = 1
141+
}
142+
132143
return &ApiClient{
133144
config: cfg,
134-
rateLimiter: rate.NewLimiter(rateLimit, 1),
145+
rateLimiter: rate.NewLimiter(rateLimit, burst),
135146
httpClient: &http.Client{
136147
// We deal with request timeouts ourselves such that we do not
137148
// time out during request or response body reads that make

0 commit comments

Comments
 (0)