Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to use HTTP client in a concurrent application

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?

like image 976
Gonzalez Avatar asked Apr 21 '16 15:04

Gonzalez


1 Answers

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.

like image 102
william.taylor.09 Avatar answered Sep 18 '22 13:09

william.taylor.09