http: maintain curl sessions
Allow curl sessions to be kept alive (ie. not ended with curl_easy_cleanup()) even after the request is completed, the number of which is determined by the configuration setting http.minSessions. Add a count for curl sessions, and update it, across slots, when starting and ending curl sessions. Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
41d5b7e362
commit
ad75ebe5b3
|
@ -1132,6 +1132,12 @@ http.maxRequests::
|
||||||
How many HTTP requests to launch in parallel. Can be overridden
|
How many HTTP requests to launch in parallel. Can be overridden
|
||||||
by the 'GIT_HTTP_MAX_REQUESTS' environment variable. Default is 5.
|
by the 'GIT_HTTP_MAX_REQUESTS' environment variable. Default is 5.
|
||||||
|
|
||||||
|
http.minSessions::
|
||||||
|
The number of curl sessions (counted across slots) to be kept across
|
||||||
|
requests. They will not be ended with curl_easy_cleanup() until
|
||||||
|
http_cleanup() is invoked. If USE_CURL_MULTI is not defined, this
|
||||||
|
value will be capped at 1. Defaults to 1.
|
||||||
|
|
||||||
http.postBuffer::
|
http.postBuffer::
|
||||||
Maximum size in bytes of the buffer used by smart HTTP
|
Maximum size in bytes of the buffer used by smart HTTP
|
||||||
transports when POSTing data to the remote system.
|
transports when POSTing data to the remote system.
|
||||||
|
|
19
http.c
19
http.c
|
@ -7,6 +7,8 @@ int active_requests;
|
||||||
int http_is_verbose;
|
int http_is_verbose;
|
||||||
size_t http_post_buffer = 16 * LARGE_PACKET_MAX;
|
size_t http_post_buffer = 16 * LARGE_PACKET_MAX;
|
||||||
|
|
||||||
|
static int min_curl_sessions = 1;
|
||||||
|
static int curl_session_count;
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
static int max_requests = -1;
|
static int max_requests = -1;
|
||||||
static CURLM *curlm;
|
static CURLM *curlm;
|
||||||
|
@ -152,6 +154,14 @@ static int http_options(const char *var, const char *value, void *cb)
|
||||||
ssl_cert_password_required = 1;
|
ssl_cert_password_required = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (!strcmp("http.minsessions", var)) {
|
||||||
|
min_curl_sessions = git_config_int(var, value);
|
||||||
|
#ifndef USE_CURL_MULTI
|
||||||
|
if (min_curl_sessions > 1)
|
||||||
|
min_curl_sessions = 1;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
if (!strcmp("http.maxrequests", var)) {
|
if (!strcmp("http.maxrequests", var)) {
|
||||||
max_requests = git_config_int(var, value);
|
max_requests = git_config_int(var, value);
|
||||||
|
@ -372,6 +382,7 @@ void http_init(struct remote *remote)
|
||||||
if (curl_ssl_verify == -1)
|
if (curl_ssl_verify == -1)
|
||||||
curl_ssl_verify = 1;
|
curl_ssl_verify = 1;
|
||||||
|
|
||||||
|
curl_session_count = 0;
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
if (max_requests < 1)
|
if (max_requests < 1)
|
||||||
max_requests = DEFAULT_MAX_REQUESTS;
|
max_requests = DEFAULT_MAX_REQUESTS;
|
||||||
|
@ -480,6 +491,7 @@ struct active_request_slot *get_active_slot(void)
|
||||||
#else
|
#else
|
||||||
slot->curl = curl_easy_duphandle(curl_default);
|
slot->curl = curl_easy_duphandle(curl_default);
|
||||||
#endif
|
#endif
|
||||||
|
curl_session_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
active_requests++;
|
active_requests++;
|
||||||
|
@ -558,9 +570,11 @@ void fill_active_slots(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (slot != NULL) {
|
while (slot != NULL) {
|
||||||
if (!slot->in_use && slot->curl != NULL) {
|
if (!slot->in_use && slot->curl != NULL
|
||||||
|
&& curl_session_count > min_curl_sessions) {
|
||||||
curl_easy_cleanup(slot->curl);
|
curl_easy_cleanup(slot->curl);
|
||||||
slot->curl = NULL;
|
slot->curl = NULL;
|
||||||
|
curl_session_count--;
|
||||||
}
|
}
|
||||||
slot = slot->next;
|
slot = slot->next;
|
||||||
}
|
}
|
||||||
|
@ -633,12 +647,13 @@ static void closedown_active_slot(struct active_request_slot *slot)
|
||||||
void release_active_slot(struct active_request_slot *slot)
|
void release_active_slot(struct active_request_slot *slot)
|
||||||
{
|
{
|
||||||
closedown_active_slot(slot);
|
closedown_active_slot(slot);
|
||||||
if (slot->curl) {
|
if (slot->curl && curl_session_count > min_curl_sessions) {
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
curl_multi_remove_handle(curlm, slot->curl);
|
curl_multi_remove_handle(curlm, slot->curl);
|
||||||
#endif
|
#endif
|
||||||
curl_easy_cleanup(slot->curl);
|
curl_easy_cleanup(slot->curl);
|
||||||
slot->curl = NULL;
|
slot->curl = NULL;
|
||||||
|
curl_session_count--;
|
||||||
}
|
}
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
fill_active_slots();
|
fill_active_slots();
|
||||||
|
|
Loading…
Reference in New Issue