Golang http. A large number of time_wait anomalies occurred during Defaultclient connection service end pressure measurement

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Today, when doing a pressure measurement scenario, a large number of time_wait connections appear on the client's server, using Golang as the client to connect to the service. After finding the information, it is resolved, as follows:

The default HTTP. Transport is opening and closing connections too quickly. Since all connections is to the same host:port combination, you need to increase to MaxIdleConnsPerHost match your value for num_coroutines . Otherwise, the transport would frequently close the extra connections, only has them reopened immediately.

You can set this globally on the default transport:

http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = numCoroutines

Or when creating your own transport

  T: = &http. transport{proxy:http. Proxyfromenvironment, Dialcontext: (&net. dialer{timeout:30 * time. Second, keepalive:30 * time. Second,}). Dialcontext, Maxidleconnsperhost:numcoroutines, maxidleconns:100, idleconntimeout:90 * Time.S Econd, Tlshandshaketimeout:10 * time. Second, Expectcontinuetimeout:1 * time. Second,}  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.