21227: Use a separate global requestLimiter for each target host.
[arvados.git] / sdk / go / arvados / limiter.go
index ac244593b2e4ba98309b593c8b0a809a623e70f7..dc944160ab2dd5d459a31fa2386ebe9a5f6bb2c3 100644 (file)
@@ -21,6 +21,7 @@ var (
 type requestLimiter struct {
        current    int64
        limit      int64
+       maxlimit   int64
        lock       sync.Mutex
        cond       *sync.Cond
        quietUntil time.Time
@@ -141,9 +142,12 @@ func (rl *requestLimiter) Report(resp *http.Response, err error) bool {
                        increase = 1
                }
                rl.limit += increase
-               if max := rl.current * 2; max > rl.limit {
+               if max := rl.current * 2; max < rl.limit {
                        rl.limit = max
                }
+               if rl.maxlimit > 0 && rl.maxlimit < rl.limit {
+                       rl.limit = rl.maxlimit
+               }
                rl.cond.Broadcast()
        }
        return false