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,}