SplitHTTP client: Add minUploadInterval (#3592)

This commit is contained in:
mmmray 2024-07-27 14:52:36 +02:00 committed by GitHub
parent 7cf5ee8afd
commit 8a4217fdf5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 188 additions and 25 deletions

View file

@ -183,6 +183,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
maxConcurrentUploads := transportConfiguration.GetNormalizedMaxConcurrentUploads()
maxUploadSize := transportConfiguration.GetNormalizedMaxUploadSize()
minUploadInterval := transportConfiguration.GetNormalizedMinUploadInterval()
if tlsConfig != nil {
requestURL.Scheme = "https"
@ -207,6 +208,8 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
requestsLimiter := semaphore.New(int(maxConcurrentUploads))
var requestCounter int64
lastWrite := time.Now()
// by offloading the uploads into a buffered pipe, multiple conn.Write
// calls get automatically batched together into larger POST requests.
// without batching, bandwidth is extremely limited.
@ -237,6 +240,14 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
}
}()
if minUploadInterval.From > 0 {
roll := time.Duration(minUploadInterval.roll()) * time.Millisecond
if time.Since(lastWrite) < roll {
time.Sleep(roll)
}
lastWrite = time.Now()
}
}
}()