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>
Tay Ray Chuan committed
Nov 27, 2009 at 23:42 UTC
ad75ebe5b3f10e77f1150d2d8111e6a60cb9039a
2 files changed
+23
-2
Documentation/config.txt
+6
@@ -1132,6 +1132,12 @@ http.maxRequests::
1132
How many HTTP requests to launch in parallel. Can be overridden
1133
by the 'GIT_HTTP_MAX_REQUESTS' environment variable. Default is 5.
1134
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
+
1141
http.postBuffer::
1142
Maximum size in bytes of the buffer used by smart HTTP
1143
transports when POSTing data to the remote system.
http.c
+17
-2
@@ -7,6 +7,8 @@ int active_requests;
7
int http_is_verbose;
8
size_t http_post_buffer = 16 * LARGE_PACKET_MAX;
9
10
+static int min_curl_sessions = 1;
11
+static int curl_session_count;
12
#ifdef USE_CURL_MULTI
13
static int max_requests = -1;
14
static CURLM *curlm;
@@ -152,6 +154,14 @@ static int http_options(const char *var, const char *value, void *cb)
154
ssl_cert_password_required = 1;
155
return 0;
156
}
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
+ }
165
#ifdef USE_CURL_MULTI
166
if (!strcmp("http.maxrequests", var)) {
167
max_requests = git_config_int(var, value);
@@ -372,6 +382,7 @@ void http_init(struct remote *remote)
382
if (curl_ssl_verify == -1)
383
curl_ssl_verify = 1;
384
385
+ curl_session_count = 0;
386
#ifdef USE_CURL_MULTI
387
if (max_requests < 1)
388
max_requests = DEFAULT_MAX_REQUESTS;
@@ -480,6 +491,7 @@ struct active_request_slot *get_active_slot(void)
491
#else
492
slot->curl = curl_easy_duphandle(curl_default);
493
#endif
494
+ curl_session_count++;
495
}
496
497
active_requests++;
@@ -558,9 +570,11 @@ void fill_active_slots(void)
570
}
571
572
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) {
575
curl_easy_cleanup(slot->curl);
576
slot->curl = NULL;
577
+ curl_session_count--;
578
}
579
slot = slot->next;
580
}
@@ -633,12 +647,13 @@ static void closedown_active_slot(struct active_request_slot *slot)
647
void release_active_slot(struct active_request_slot *slot)
648
{
649
closedown_active_slot(slot);
636
- if (slot->curl) {
650
+ if (slot->curl && curl_session_count > min_curl_sessions) {
651
#ifdef USE_CURL_MULTI
652
curl_multi_remove_handle(curlm, slot->curl);
653
#endif
654
curl_easy_cleanup(slot->curl);
655
slot->curl = NULL;
656
+ curl_session_count--;
657
}
658
#ifdef USE_CURL_MULTI
659
fill_active_slots();