From: wessels <> Date: Wed, 25 Mar 1998 00:29:43 +0000 (+0000) Subject: dynamically calculate some hash table sizes X-Git-Tag: SQUID_3_0_PRE1~3758 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa9e2cabe92377c63660c4535bfd1b5f0d42d90a;p=thirdparty%2Fsquid.git dynamically calculate some hash table sizes --- diff --git a/src/client_db.cc b/src/client_db.cc index 3dc5dd8d94..2dd37ef95f 100644 --- a/src/client_db.cc +++ b/src/client_db.cc @@ -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, diff --git a/src/comm.cc b/src/comm.cc index 2ac0a64f41..da6d6a69d6 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -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 */ diff --git a/src/fqdncache.cc b/src/fqdncache.cc index 2c780edabd..c6a87720b9 100644 --- a/src/fqdncache.cc +++ b/src/fqdncache.cc @@ -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); diff --git a/src/ipcache.cc b/src/ipcache.cc index ea532e1a94..ccaa283ed7 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -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); diff --git a/src/net_db.cc b/src/net_db.cc index 56ee72579a..1245017e8b 100644 --- a/src/net_db.cc +++ b/src/net_db.cc @@ -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", diff --git a/src/protos.h b/src/protos.h index beece5e6d8..19218b88a8 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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 *);