Skip to content

Commit

Permalink
enable connection reuse in libcurl
Browse files Browse the repository at this point in the history
The Connection Reuse section of the Everything curl book explains how this
works:

https://everything.curl.dev/libcurl/connectionreuse

> When you are using the easy API, or, more specifically, curl_easy_perform(),
> libcurl will keep the pool associated with the specific easy handle. Then
> reusing the same easy handle will ensure it can reuse its connection.

Before, in the `HttpClient::perform` method, a new curl handle was created
upon every invocation, which meant that there was no opportunity to reuse
connections from the underlying connection pool.

By making the curl handle static, it ensures that the same one remains in use,
thus providing the means to reuse the established connection pool.

Fixes Netflix-Skunkworks#51.
  • Loading branch information
copperlight committed Oct 19, 2023
1 parent 79a2713 commit 4e7dd02
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion spectator/http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ auto HttpClient::perform(const char* method, const std::string& url,
int attempt_number) const -> HttpResponse {
LogEntry entry{registry_, method, url};

CurlHandle curl;
static CurlHandle curl;
auto total_timeout = config_.connect_timeout + config_.read_timeout;
curl.set_timeout(total_timeout);
curl.set_connect_timeout(config_.connect_timeout);
Expand Down

0 comments on commit 4e7dd02

Please sign in to comment.