Best way to use HTTP client in a concurrent application

百般思念 提交于 2020-01-23 04:49:07

问题


First I'll describe my case. I have to do HTTPS requests to several APIs from my application and they should be ran concurrently. I want to know if I should use a separate HTTP client per goroutine or I can share one client across all goroutines. Of course I'd like to enjoy connection reusing/pooling offered by the HTTP client, but I am concerned about it being thread(aka goroutine)-safe and if the client will run requests concurrently or they'll in fact be sequenced?


回答1:


Http clients are thread safe according to the docs (https://golang.org/src/net/http/client.go):

Clients are safe for concurrent use by multiple goroutines.



来源:https://stackoverflow.com/questions/36773837/best-way-to-use-http-client-in-a-concurrent-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!