Home >Backend Development >C++ >Is Creating a New HttpClient for Each Web API Call Truly Efficient?
In the Web API client application, the best life cycle of the HTTPClient object has been controversial. Some people advocate creating a new example for each call, while others advocate calling and reusing a single example multiple times.
Create a new httpclient
Create a new HTTPClient for each request to introduce some expenses, including:
credentials and cookie management:HTTPClientHandler maintenance credentials and cookies, these credentials and cookies are designed to reuse them across. The efficiency of resetting these values separately for each request is low.
Connection pool: Reuse the TCP/IP connection through HTTPClient to reuse the TCP/IP connection to avoid re -establishing the connection for each request to improve performance.
Status processing program:
HTTPMESSAGEHANDLERS can maintain the application -level state between requests, which is difficult to achieve each time the HTTPClient instance is instantiated.The above is the detailed content of Is Creating a New HttpClient for Each Web API Call Truly Efficient?. For more information, please follow other related articles on the PHP Chinese website!