21227: Use a separate global requestLimiter for each target host.
[arvados.git] / sdk / go / arvados / limiter.go
index 0fc6cc09648a79cf491dcb60d3ff0c7643e3a449..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
@@ -144,6 +145,9 @@ func (rl *requestLimiter) Report(resp *http.Response, err error) bool {
                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