]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
dynamically calculate some hash table sizes
authorwessels <>
Wed, 25 Mar 1998 00:29:43 +0000 (00:29 +0000)
committerwessels <>
Wed, 25 Mar 1998 00:29:43 +0000 (00:29 +0000)
src/client_db.cc
src/comm.cc
src/fqdncache.cc
src/ipcache.cc
src/net_db.cc
src/protos.h

index 3dc5dd8d948f3b6303ca884419e033be41489459..2dd37ef95f2dd1e1e3a7dfb2caebe2bd11f649d7 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_db.cc,v 1.24 1998/03/13 05:38:13 wessels Exp $
+ * $Id: client_db.cc,v 1.25 1998/03/24 17:29:43 wessels Exp $
  *
  * DEBUG: section 0     Client Database
  * AUTHOR: Duane Wessels
@@ -50,7 +50,7 @@ clientdbInit(void)
 {
     if (client_table)
        return;
-    client_table = hash_create((HASHCMP *) strcmp, 229, hash_string);
+    client_table = hash_create((HASHCMP *) strcmp, 467, hash_string);
     cachemgrRegister("client_list",
        "Cache Client List",
        clientdbDump,
index 2ac0a64f41eb3632fb7e329cb3b19b912097ccae..da6d6a69d6d34c764074bc847b04b521b902655f 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm.cc,v 1.234 1998/03/20 06:51:44 wessels Exp $
+ * $Id: comm.cc,v 1.235 1998/03/24 17:29:44 wessels Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -1420,32 +1420,24 @@ commHandleWrite(int fd, void *data)
 void
 comm_write(int fd, char *buf, int size, CWCB * handler, void *handler_data, FREE * free_func)
 {
-    CommWriteStateData *state = NULL;
+    CommWriteStateData *state = fd_table[fd].rwstate;
     debug(5, 5) ("comm_write: FD %d: sz %d: hndl %p: data %p.\n",
        fd, size, handler, handler_data);
-    if (fd_table[fd].rwstate) {
+    if (NULL != state) {
        debug(5, 1) ("comm_write: fd_table[%d].rwstate != NULL", fd);
-       state = fd_table[fd].rwstate;
-       debug(5, 1) ("comm_write: %d'%s',(%d,%d)'%s'\n", size, buf, state->size,
-           state->offset, state->buf);
-       safe_free(fd_table[fd].rwstate);
+       safe_free(state);
        fd_table[fd].rwstate = NULL;
     }
-    assert(fd_table[fd].rwstate == NULL);
-    state = xcalloc(1, sizeof(CommWriteStateData));
+    assert(state == NULL);
+    fd_table[fd].rwstate = state = xcalloc(1, sizeof(CommWriteStateData));
     state->buf = buf;
     state->size = size;
     state->offset = 0;
     state->handler = handler;
     state->handler_data = handler_data;
     state->free_func = free_func;
-    fd_table[fd].rwstate = state;
     cbdataLock(handler_data);
-    commSetSelect(fd,
-       COMM_SELECT_WRITE,
-       commHandleWrite,
-       fd_table[fd].rwstate,
-       0);
+    commSetSelect(fd, COMM_SELECT_WRITE, commHandleWrite, state, 0);
 }
 
 /* a wrapper around comm_write to allow for MemBuf to comm_written in a snap */
index 2c780edabd89eaf7e3bbdb1ef543dc85d9612615..c6a87720b9535c6177953c5088595d9c586862fc 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: fqdncache.cc,v 1.92 1998/03/21 22:06:00 kostas Exp $
+ * $Id: fqdncache.cc,v 1.93 1998/03/24 17:29:45 wessels Exp $
  *
  * DEBUG: section 35    FQDN Cache
  * AUTHOR: Harvest Derived
@@ -616,16 +616,17 @@ fqdncache_dnsDispatch(dnsserver_t * dns, fqdncache_entry * f)
 void
 fqdncache_init(void)
 {
+    int n;
     if (fqdn_table)
        return;
     debug(35, 3) ("Initializing FQDN Cache...\n");
     memset(&FqdncacheStats, '\0', sizeof(FqdncacheStats));
-    /* small hash table */
-    fqdn_table = hash_create(urlcmp, 229, hash4);
     fqdncache_high = (long) (((float) MAX_FQDN *
            (float) FQDN_HIGH_WATER) / (float) 100);
     fqdncache_low = (long) (((float) MAX_FQDN *
            (float) FQDN_LOW_WATER) / (float) 100);
+    n = hashPrime(fqdncache_high / 4);
+    fqdn_table = hash_create(urlcmp, n, hash4);
     cachemgrRegister("fqdncache",
        "FQDN Cache Stats and Contents",
        fqdnStats, 0);
index ea532e1a94df9c66aedc3213dc74d7e65e4b5e60..ccaa283ed7a1df8625c6d2ae1ecafff27c71afbe 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ipcache.cc,v 1.170 1998/03/21 22:06:01 kostas Exp $
+ * $Id: ipcache.cc,v 1.171 1998/03/24 17:29:46 wessels Exp $
  *
  * DEBUG: section 14    IP Cache
  * AUTHOR: Harvest Derived
@@ -668,6 +668,7 @@ ipcache_dnsDispatch(dnsserver_t * dns, ipcache_entry * i)
 void
 ipcache_init(void)
 {
+    int n;
     debug(14, 3) ("Initializing IP Cache...\n");
 
     memset(&IpcacheStats, '\0', sizeof(IpcacheStats));
@@ -681,7 +682,6 @@ ipcache_init(void)
        debug(14, 1) ("Successful DNS name lookup tests...\n");
     }
 
-    ip_table = hash_create(urlcmp, 229, hash4);                /* small hash table */
     memset(&static_addrs, '\0', sizeof(ipcache_addrs));
     static_addrs.in_addrs = xcalloc(1, sizeof(struct in_addr));
     static_addrs.bad_mask = xcalloc(1, sizeof(unsigned char));
@@ -690,6 +690,8 @@ ipcache_init(void)
            (float) Config.ipcache.high) / (float) 100);
     ipcache_low = (long) (((float) Config.ipcache.size *
            (float) Config.ipcache.low) / (float) 100);
+    n = hashPrime(ipcache_high / 4);
+    ip_table = hash_create(urlcmp, n, hash4);
     cachemgrRegister("ipcache",
        "IP Cache Stats and Contents",
        stat_ipcache_get, 0);
index 56ee72579aaca947daa7ce7351f63d914c45b846..1245017e8bcca4139dbca69e90c8cfe286fca186 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: net_db.cc,v 1.75 1998/03/21 22:06:02 kostas Exp $
+ * $Id: net_db.cc,v 1.76 1998/03/24 17:29:47 wessels Exp $
  *
  * DEBUG: section 37    Network Measurement Database
  * AUTHOR: Duane Wessels
@@ -475,10 +475,13 @@ void
 netdbInit(void)
 {
 #if USE_ICMP
+    int n;
     if (addr_table)
        return;
-    addr_table = hash_create((HASHCMP *) strcmp, 229, hash_string);
-    host_table = hash_create((HASHCMP *) strcmp, 467, hash_string);
+    n = hashPrime(Config.Netdb.high / 4);
+    addr_table = hash_create((HASHCMP *) strcmp, n, hash_string);
+    n = hashPrime(3 * Config.Netdb.high / 4);
+    host_table = hash_create((HASHCMP *) strcmp, n, hash_string);
     eventAdd("netdbSaveState", netdbSaveState, NULL, 3617);
     netdbReloadState();
     cachemgrRegister("netdb",
index beece5e6d811e810dc64aaf57633dc7183729f9c..19218b88a8ce51cea1495de5a9baf388d42b35ea 100644 (file)
@@ -205,6 +205,7 @@ extern int hash_delete(hash_table *, const char *);
 extern int hash_delete_link(hash_table *, hash_link *);
 extern void hash_join(hash_table *, hash_link *);
 extern int hash_remove_link(hash_table *, hash_link *);
+extern int hashPrime(int n);
 
 /* searching, accessing */
 extern hash_link *hash_lookup(hash_table *, const void *);