-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set Keep-Alive to the Header to request to S3? #829
Comments
Hi @skyleelove, by default the SDK will use connection pooling and keep alive for all requests made to S3. These connections may be closed server side if they are not reused within a short duration though. |
Hi,jasdel Thanks for your answer.I get so many TIME_WAIT when I put object to S3 using the sdk for go.How can I do for solve the problem? |
Thanks for the update @skyleelove. Are you getting the If you have any sample code that reproduces the issue it may be helpful identifying the issue you're seeing. |
Thanks a lot . |
Now I update the sdk to v1.4.8 .It still has so mang TIME_WAIT |
Thanks for the update. How does your code initialize the S3 client, and is the s3 client instance shared between all of your upload requests? Or is a new client created for each upload? The SDK's service clients are safe to shared among gorouties, so you shouldn't need to create a new client for each goroutine. |
var s3Client *s3.S3 |
func init() { Here are init client |
Do you see a TIME_WAIT for each sock for each put or only some of the puts? Its possible that S3 server is closing the connection because it has not been reused within a short enough period. Possibly within the period your code is using. Have you tried to upload the requests in parallel with a smaller delay between the uploads? This might help take advantage of the reused connection before S3 closes it. |
Thanks a lot . net.ipv4.tcp_syncookies = 1 But it still has so many TIME_WAIT. Should I change my code to use the sdk to solve the problem with your suggestion. |
The theory behind the change I suggest is that by using a shorter delay period between upload your increase the probability of reusing a previous HTTP TCP connection. Are you running into an issue where you're running out of sockets/handles that is related to the TIME_WAIT? If so I think it would be good to check to make sure that your code is closing all files that are being put to S3. If given an If this isn't the issue you could try setting the |
Thanks a lot |
Hi, I try it ,but it does not work. |
Hi,jasdel I find that every connection is disconnected by client,so which function of the sdk to break the connection.I can not find it. |
Hi @skyleelove, the SDK does not directly close the HTTP TCP connections. This is managed by the Go std libraries http.Client. if the connection is being closed, I think it is being closed server side. We're you able to set the S3ForcePathStyle config value to see if that helped in this case? |
Hi,jasdel this is old: func (c *Config) WithHTTPClient(client *http.Client) *Config {
c.HTTPClient = client
return c
} this is new that I change: func (c *Config) WithHTTPClient(client *http.Client) *Config {
ct := &http.Client{}
ts := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
MaxIdleConnsPerHost: 100,
TLSHandshakeTimeout: 3 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
ct.Transport = ts
c.HTTPClient = ct
return c
} I set MaxIdleConnsPerHost to 100 in order to increase the connection number of same host to solve.And I want to kown the suggestion of you about this change.Thanks a lot. |
@skyleelove, Increasing the number of idle connections will improve the retention of connections in the pool. There looks to be a known issue (golang/go#13801) in Go's How many requests at once is your application making? To just specify a custom sess := session.New()
svc := s3.New(sess, &aws.Config{HTTPClient: &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
MaxIdleConnsPerHost: 100,
TLSHandshakeTimeout: 3 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}}) The |
Thanks a lot ,I will change the code. |
Hi,
I want to set a long connection to s3,how i can use the sdk to do this?Thanks a lot
The text was updated successfully, but these errors were encountered: