Skip to content

Commit ad75ebe

Browse files
rctaygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41d5b7e commit ad75ebe

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,12 @@ http.maxRequests::
11321132
How many HTTP requests to launch in parallel. Can be overridden
11331133
by the 'GIT_HTTP_MAX_REQUESTS' environment variable. Default is 5.
11341134

1135+
http.minSessions::
1136+
The number of curl sessions (counted across slots) to be kept across
1137+
requests. They will not be ended with curl_easy_cleanup() until
1138+
http_cleanup() is invoked. If USE_CURL_MULTI is not defined, this
1139+
value will be capped at 1. Defaults to 1.
1140+
11351141
http.postBuffer::
11361142
Maximum size in bytes of the buffer used by smart HTTP
11371143
transports when POSTing data to the remote system.

http.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ int active_requests;
77
int http_is_verbose;
88
size_t http_post_buffer = 16 * LARGE_PACKET_MAX;
99

10+
static int min_curl_sessions = 1;
11+
static int curl_session_count;
1012
#ifdef USE_CURL_MULTI
1113
static int max_requests = -1;
1214
static CURLM *curlm;
@@ -152,6 +154,14 @@ static int http_options(const char *var, const char *value, void *cb)
152154
ssl_cert_password_required = 1;
153155
return 0;
154156
}
157+
if (!strcmp("http.minsessions", var)) {
158+
min_curl_sessions = git_config_int(var, value);
159+
#ifndef USE_CURL_MULTI
160+
if (min_curl_sessions > 1)
161+
min_curl_sessions = 1;
162+
#endif
163+
return 0;
164+
}
155165
#ifdef USE_CURL_MULTI
156166
if (!strcmp("http.maxrequests", var)) {
157167
max_requests = git_config_int(var, value);
@@ -372,6 +382,7 @@ void http_init(struct remote *remote)
372382
if (curl_ssl_verify == -1)
373383
curl_ssl_verify = 1;
374384

385+
curl_session_count = 0;
375386
#ifdef USE_CURL_MULTI
376387
if (max_requests < 1)
377388
max_requests = DEFAULT_MAX_REQUESTS;
@@ -480,6 +491,7 @@ struct active_request_slot *get_active_slot(void)
480491
#else
481492
slot->curl = curl_easy_duphandle(curl_default);
482493
#endif
494+
curl_session_count++;
483495
}
484496

485497
active_requests++;
@@ -558,9 +570,11 @@ void fill_active_slots(void)
558570
}
559571

560572
while (slot != NULL) {
561-
if (!slot->in_use && slot->curl != NULL) {
573+
if (!slot->in_use && slot->curl != NULL
574+
&& curl_session_count > min_curl_sessions) {
562575
curl_easy_cleanup(slot->curl);
563576
slot->curl = NULL;
577+
curl_session_count--;
564578
}
565579
slot = slot->next;
566580
}
@@ -633,12 +647,13 @@ static void closedown_active_slot(struct active_request_slot *slot)
633647
void release_active_slot(struct active_request_slot *slot)
634648
{
635649
closedown_active_slot(slot);
636-
if (slot->curl) {
650+
if (slot->curl && curl_session_count > min_curl_sessions) {
637651
#ifdef USE_CURL_MULTI
638652
curl_multi_remove_handle(curlm, slot->curl);
639653
#endif
640654
curl_easy_cleanup(slot->curl);
641655
slot->curl = NULL;
656+
curl_session_count--;
642657
}
643658
#ifdef USE_CURL_MULTI
644659
fill_active_slots();

0 commit comments

Comments
 (0)