Last active
December 2, 2019 15:09
-
-
Save AVoskoboinikov/7be5f702622bcf37d84601685812cd47 to your computer and use it in GitHub Desktop.
SQS Requests and connections with TIME_WAIT status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/sqs" | |
"net" | |
"net/http" | |
"time" | |
) | |
func main() { | |
qName := "connection-reset-test" | |
threads := 160 | |
config := &aws.Config{ | |
Endpoint: aws.String("sqs.us-east-1.amazonaws.com"), // VPC endpoint here | |
Region: aws.String("us-east-1"), | |
HTTPClient: &http.Client{ | |
Transport: &http.Transport{ | |
Proxy: http.ProxyFromEnvironment, | |
DialContext: (&net.Dialer{ | |
Timeout: 30 * time.Second, | |
KeepAlive: 30 * time.Second, | |
}).DialContext, | |
MaxIdleConns: 380, | |
MaxIdleConnsPerHost: 160, | |
IdleConnTimeout: 90 * time.Second, | |
TLSHandshakeTimeout: 10 * time.Second, | |
ExpectContinueTimeout: 1 * time.Second, | |
}, | |
}, | |
} | |
sess := session.Must(session.NewSession()) | |
sqsClient := sqs.New(sess, config) | |
queueParams := &sqs.CreateQueueInput{QueueName: aws.String(qName)} | |
res, err := sqsClient.CreateQueue(queueParams) | |
if err != nil { | |
panic(fmt.Sprintf("failed to create queue: %s", err)) | |
} | |
for i := 0; i < threads; i++ { | |
go func() { | |
for { | |
msgParams := &sqs.SendMessageInput{ | |
QueueUrl: res.QueueUrl, | |
MessageBody: aws.String("42"), | |
} | |
_, err := sqsClient.SendMessage(msgParams) | |
if err != nil { | |
fmt.Println() | |
fmt.Println(fmt.Sprintf("got an error from sqs: %s", err)) | |
fmt.Println() | |
} | |
} | |
}() | |
} | |
time.Sleep(5 * time.Minute) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment