Limit concurrent S3 connections per host #186
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit limits the number of concurrent connections to encourage
connection reuse.
MaxIdleConnsPerHost
was already set to workaroundgolang/go#13801 ("issue which made Go consume
all ephemeral ports").
We observed a similar issue when starting up Loki (using weaveworks
common/aws
throught Cortex) which resulted in thousands of very smallS3 requests until memcached was seeded. This failed because of ephemeral
port exhaustion: while the application in fact would have reused
connections, it already failed as it sent all of them concurrently until
most of the requests failed.
MaxConnsPerHost
can be used to limit the overall number of parallelconnections.
An alternative solution would be to queue requests in the application, but the golang HTTP client already has a queue. Whether a maximum of 100 parallel requests is reasonable or too small might be subject of discussion. I'm not sure if there is a relevant use case of more than 100 parallel S3 streams per instance.
In my experiments, a connection limit larger than
MaxIdleConns
resulted in few connections piling up, but in a rate the system could handle well (with other words: they went through theirTIME_WAIT
window and were removed from the connection list without the system getting close to the ephemeral connection limit).