]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
multi: use larger dns hash table for multi interface
authorDaniel Stenberg <daniel@haxx.se>
Sat, 27 Aug 2022 12:48:13 +0000 (14:48 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 28 Aug 2022 22:07:09 +0000 (00:07 +0200)
Have curl_multi_init() use a much larger DNS hash table than used for
the easy interface to scale and perform better when used with _many_
host names.

curl_share_init() sets an in-between size.

Inspired-by: Ivan Tsybulin
See #9340
Closes #9376

lib/easy.c
lib/hostip.c
lib/hostip.h
lib/multi.c
lib/multiif.h
lib/share.c
tests/unit/unit1305.c

index e17a461e8449f380acd386421967efc36bbb64ce..978ea5ac301a357c33418d60e3f6eb41037a7ad6 100644 (file)
@@ -725,7 +725,7 @@ static CURLcode easy_perform(struct Curl_easy *data, bool events)
   else {
     /* this multi handle will only ever have a single easy handled attached
        to it, so make it use minimal hashes */
-    multi = Curl_multi_handle(1, 3);
+    multi = Curl_multi_handle(1, 3, 7);
     if(!multi)
       return CURLE_OUT_OF_MEMORY;
     data->multi_easy = multi;
index 99779044c5f1b0fc249fe91fc5604d21f4506e0e..bb94520acf5bf1dacde46f0e3bff6f47663827a0 100644 (file)
@@ -1005,9 +1005,9 @@ static void freednsentry(void *freethis)
 /*
  * Curl_init_dnscache() inits a new DNS cache.
  */
-void Curl_init_dnscache(struct Curl_hash *hash)
+void Curl_init_dnscache(struct Curl_hash *hash, int size)
 {
-  Curl_hash_init(hash, 7, Curl_hash_str, Curl_str_key_compare,
+  Curl_hash_init(hash, size, Curl_hash_str, Curl_str_key_compare,
                  freednsentry);
 }
 
index 4b603378bd5abe4b8f405da1e0cdfcd015e92ffc..9d3170737c03cd19fce85f46a43f5ec92ccb7d9c 100644 (file)
@@ -132,7 +132,7 @@ void Curl_resolv_unlock(struct Curl_easy *data,
                         struct Curl_dns_entry *dns);
 
 /* init a new dns cache */
-void Curl_init_dnscache(struct Curl_hash *hash);
+void Curl_init_dnscache(struct Curl_hash *hash, int hashsize);
 
 /* prune old entries from the DNS cache */
 void Curl_hostcache_prune(struct Curl_easy *data);
index ac753d2120a6c02c490e9213cf4c2bc0412eb2e4..5340a0c8a5e6f0d7ea4c67e605290cfbde1fd37b 100644 (file)
 #define CURL_CONNECTION_HASH_SIZE 97
 #endif
 
+#ifndef CURL_DNS_HASH_SIZE
+#define CURL_DNS_HASH_SIZE 71
+#endif
+
 #define CURL_MULTI_HANDLE 0x000bab1e
 
 #define GOOD_MULTI_HANDLE(x) \
@@ -388,7 +392,8 @@ static CURLMcode multi_addmsg(struct Curl_multi *multi,
 }
 
 struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */
-                                     int chashsize) /* connection hash */
+                                     int chashsize, /* connection hash */
+                                     int dnssize) /* dns hash */
 {
   struct Curl_multi *multi = calloc(1, sizeof(struct Curl_multi));
 
@@ -397,7 +402,7 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */
 
   multi->magic = CURL_MULTI_HANDLE;
 
-  Curl_init_dnscache(&multi->hostcache);
+  Curl_init_dnscache(&multi->hostcache, dnssize);
 
   sh_init(&multi->sockhash, hashsize);
 
@@ -451,7 +456,8 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */
 struct Curl_multi *curl_multi_init(void)
 {
   return Curl_multi_handle(CURL_SOCKET_HASH_TABLE_SIZE,
-                           CURL_CONNECTION_HASH_SIZE);
+                           CURL_CONNECTION_HASH_SIZE,
+                           CURL_DNS_HASH_SIZE);
 }
 
 CURLMcode curl_multi_add_handle(struct Curl_multi *multi,
index e0aa00b05e1287c59a19ec7ea7149f921c925d10..0cb9d4f7f2a7b0e775d5bad8671df0495986bdca 100644 (file)
@@ -42,8 +42,9 @@ bool Curl_is_in_callback(struct Curl_easy *easy);
 CURLcode Curl_preconnect(struct Curl_easy *data);
 
 /* Internal version of curl_multi_init() accepts size parameters for the
-   socket and connection hashes */
-struct Curl_multi *Curl_multi_handle(int hashsize, int chashsize);
+   socket, connection and dns hashes */
+struct Curl_multi *Curl_multi_handle(int hashsize, int chashsize,
+                                     int dnssize);
 
 /* the write bits start at bit 16 for the *getsock() bitmap */
 #define GETSOCK_WRITEBITSTART 16
index 8b18360624b430fe18f36f976d45b42dd29b2da9..1a083e72a085f2160dcc7fbe828331318e359149 100644 (file)
@@ -41,7 +41,7 @@ curl_share_init(void)
   if(share) {
     share->magic = CURL_GOOD_SHARE;
     share->specifier |= (1<<CURL_LOCK_DATA_SHARE);
-    Curl_init_dnscache(&share->hostcache);
+    Curl_init_dnscache(&share->hostcache, 23);
   }
 
   return share;
index c35d448fe7ef0b3cab56148d0f3972493731cfba..815d3038848a784c8e8fa9e2ad4dae3a1d845eb6 100644 (file)
@@ -54,7 +54,7 @@ static CURLcode unit_setup(void)
     return CURLE_OUT_OF_MEMORY;
   }
 
-  Curl_init_dnscache(&hp);
+  Curl_init_dnscache(&hp, 7);
   return CURLE_OK;
 }