1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

easy_perform: use *multi_timeout() to get wait times

... and trim the threaded Curl_resolver_getsock() to return zero
millisecond wait times during the first three milliseconds so that
localhost or names in the OS resolver cache gets detected and used
faster.

Closes #2685
This commit is contained in:
Daniel Stenberg 2018-06-26 18:11:32 +02:00
parent b0a365f8a0
commit 3ef67c6861
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 9 additions and 20 deletions

View File

@ -574,10 +574,10 @@ int Curl_resolver_getsock(struct connectdata *conn,
(void)socks; (void)socks;
(void)numsocks; (void)numsocks;
ms = Curl_timediff(Curl_now(), reslv->start); ms = Curl_timediff(Curl_now(), reslv->start);
if(ms < 10) if(ms < 3)
milli = ms/3; milli = 0;
else if(ms <= 50) else if(ms <= 50)
milli = 10; milli = ms/3;
else if(ms <= 250) else if(ms <= 250)
milli = 50; milli = 50;
else else

View File

@ -661,38 +661,27 @@ static CURLcode easy_transfer(struct Curl_multi *multi)
bool done = FALSE; bool done = FALSE;
CURLMcode mcode = CURLM_OK; CURLMcode mcode = CURLM_OK;
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct curltime before;
int without_fds = 0; /* count number of consecutive returns from
curl_multi_wait() without any filedescriptors */
while(!done && !mcode) { while(!done && !mcode) {
int still_running = 0; int still_running = 0;
int rc; int rc;
before = Curl_now();
mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc); mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc);
if(!mcode) { if(!mcode) {
if(!rc) { if(!rc) {
struct curltime after = Curl_now(); long sleep_ms;
/* If it returns without any filedescriptor instantly, we need to /* If it returns without any filedescriptor instantly, we need to
avoid busy-looping during periods where it has nothing particular avoid busy-looping during periods where it has nothing particular
to wait for */ to wait for */
if(Curl_timediff(after, before) <= 10) { curl_multi_timeout(multi, &sleep_ms);
without_fds++; if(sleep_ms) {
if(without_fds > 2) { if(sleep_ms > 1000)
int sleep_ms = without_fds < 10 ? (1 << (without_fds - 1)) : 1000; sleep_ms = 1000;
Curl_wait_ms(sleep_ms); Curl_wait_ms((int)sleep_ms);
} }
} }
else
/* it wasn't "instant", restart counter */
without_fds = 0;
}
else
/* got file descriptor, restart counter */
without_fds = 0;
mcode = curl_multi_perform(multi, &still_running); mcode = curl_multi_perform(multi, &still_running);
} }