summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2018-06-26 18:11:32 +0200
committerDaniel Stenberg <daniel@haxx.se>2018-06-26 18:14:52 +0200
commit16eb618d77016cd647a3ce60f916653913716f38 (patch)
treeaa5aa4e6615afde6467e3bf3d783afd4307f2ba9
parentf762fec323f36fd7da7ad6eddfbbae940ec3229e (diff)
downloadcurl-bagder/easy-perform-loop.tar.gz
easy_perform: use *multi_timeout() to get wait timesbagder/easy-perform-loop
... and trim the threaded Curl_resolver_getsock() to return zero millisecond wait times during the first 10 milliseconds so that localhost or names in the OS resolver cache gets detected and used faster.
-rw-r--r--lib/asyn-thread.c6
-rw-r--r--lib/easy.c23
2 files changed, 9 insertions, 20 deletions
diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c
index 894ca459b..c7c1a0086 100644
--- a/lib/asyn-thread.c
+++ b/lib/asyn-thread.c
@@ -574,10 +574,10 @@ int Curl_resolver_getsock(struct connectdata *conn,
(void)socks;
(void)numsocks;
ms = Curl_timediff(Curl_now(), reslv->start);
- if(ms < 10)
- milli = ms/3;
+ if(ms < 3)
+ milli = 0;
else if(ms <= 50)
- milli = 10;
+ milli = ms/3;
else if(ms <= 250)
milli = 50;
else
diff --git a/lib/easy.c b/lib/easy.c
index bf85075e1..5af90e326 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -661,38 +661,27 @@ static CURLcode easy_transfer(struct Curl_multi *multi)
bool done = FALSE;
CURLMcode mcode = CURLM_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) {
int still_running = 0;
int rc;
- before = Curl_now();
mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc);
if(!mcode) {
if(!rc) {
- struct curltime after = Curl_now();
+ long sleep_ms;
/* If it returns without any filedescriptor instantly, we need to
avoid busy-looping during periods where it has nothing particular
to wait for */
- if(Curl_timediff(after, before) <= 10) {
- without_fds++;
- if(without_fds > 2) {
- int sleep_ms = without_fds < 10 ? (1 << (without_fds - 1)) : 1000;
- Curl_wait_ms(sleep_ms);
- }
+ curl_multi_timeout(multi, &sleep_ms);
+ if(sleep_ms) {
+ if(sleep_ms > 1000)
+ sleep_ms = 1000;
+ 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);
}