Hi! On Tue, Apr 10, 2018 at 06:14:46AM -0700, Sun Frank wrote: > my question is how to reuse underlying TCP connection when doing a lot of > frequent short HTTP requests using golang?
This happens by default: https://play.golang.org/p/XnzQoGqQlno > they say the key is to close resp.Body Yes, but any correct code should close all resources. Not closing resp.Body is just one of ways how bad code may break things (like reuse of TCP connections). > then I start a http server: > python3 -m http.server 8080 > and then i start package capture: > sudo tcpdump -i lo -s 0 -w /tmp/p1.pcap dst port 8080 > then run: go run main.go, i still got 3 times of TCP handshake, even after > i change MaxIdleConnections to 1 - MaxIdleConnections doesn't limit amount of connections client may open. - New connections may open because server closes old ones, not because of client setup. - Server may close connections for many reasons, for ex. if it see header "Connection: close" with protocol HTTP/1.1 or if it see protocol HTTP/1.0 without "Connection: keep-alive" or a lot of other reasons. -- WBR, Alex. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.