From: wessels <> Date: Fri, 16 Apr 1999 07:00:49 +0000 (+0000) Subject: comm_incoming crap for internal DNS X-Git-Tag: SQUID_3_0_PRE1~2280 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef523f990009da27ce7bbac6ceb4b96301d09eb9;p=thirdparty%2Fsquid.git comm_incoming crap for internal DNS Semi-better retransmit algorithm. Use nameserver % num_sends --- diff --git a/src/comm_select.cc b/src/comm_select.cc index 005f9e4c59..26143335e1 100644 --- a/src/comm_select.cc +++ b/src/comm_select.cc @@ -1,6 +1,6 @@ /* - * $Id: comm_select.cc,v 1.29 1999/01/18 22:23:33 wessels Exp $ + * $Id: comm_select.cc,v 1.30 1999/04/16 01:00:49 wessels Exp $ * * DEBUG: section 5 Socket Functions * @@ -55,6 +55,7 @@ static int examine_select(fd_set *, fd_set *); #endif static int fdIsHttp(int fd); static int fdIsIcp(int fd); +static int fdIsDns(int fd); static int commDeferRead(int fd); static void checkTimeouts(void); static OBJH commIncomingStats; @@ -122,10 +123,13 @@ static int nwritefds; #define INCOMING_FACTOR 5 #define MAX_INCOMING_INTERVAL (MAX_INCOMING_INTEGER << INCOMING_FACTOR) static int icp_io_events = 0; +static int dns_io_events = 0; static int http_io_events = 0; static int incoming_icp_interval = 16 << INCOMING_FACTOR; +static int incoming_dns_interval = 16 << INCOMING_FACTOR; static int incoming_http_interval = 16 << INCOMING_FACTOR; #define commCheckICPIncoming (++icp_io_events > (incoming_icp_interval>> INCOMING_FACTOR)) +#define commCheckDNSIncoming (++dns_io_events > (incoming_dns_interval>> INCOMING_FACTOR)) #define commCheckHTTPIncoming (++http_io_events > (incoming_http_interval>> INCOMING_FACTOR)) static int @@ -147,6 +151,14 @@ fdIsIcp(int fd) return 0; } +static int +fdIsDns(int fd) +{ + if (fd == DnsSocket) + return 1; + return 0; +} + static int fdIsHttp(int fd) { @@ -238,6 +250,27 @@ comm_poll_icp_incoming(void) statHistCount(&Counter.comm_icp_incoming, nevents); } +static void +comm_poll_dns_incoming(void) +{ + int nfds = 0; + int fds[2]; + int nevents; + dns_io_events = 0; + if (DnsSocket < 0) + return; + fds[nfds++] = DnsSocket; + nevents = comm_check_incoming_poll_handlers(nfds, fds); + incoming_dns_interval += Config.comm_incoming.dns_average - nevents; + if (incoming_dns_interval < Config.comm_incoming.dns_min_poll) + incoming_dns_interval = Config.comm_incoming.dns_min_poll; + if (incoming_dns_interval > MAX_INCOMING_INTERVAL) + incoming_dns_interval = MAX_INCOMING_INTERVAL; + if (nevents > INCOMING_DNS_MAX) + nevents = INCOMING_DNS_MAX; + statHistCount(&Counter.comm_dns_incoming, nevents); +} + static void comm_poll_http_incoming(void) { @@ -277,6 +310,7 @@ comm_poll(int msec) unsigned long nfds; int num; int callicp = 0, callhttp = 0; + int calldns = 0; static time_t last_timeout = 0; double timeout = current_dtime + (msec / 1000.0); double start; @@ -290,9 +324,11 @@ comm_poll(int msec) #endif if (commCheckICPIncoming) comm_poll_icp_incoming(); + if (commCheckDNSIncoming) + comm_poll_dns_incoming(); if (commCheckHTTPIncoming) comm_poll_http_incoming(); - callicp = callhttp = 0; + callicp = calldns = callhttp = 0; nfds = 0; maxfd = Biggest_FD + 1; for (i = 0; i < maxfd; i++) { @@ -350,6 +386,10 @@ comm_poll(int msec) callicp = 1; continue; } + if (fdIsDns(fd)) { + calldns = 1; + continue; + } if (fdIsHttp(fd)) { callhttp = 1; continue; @@ -364,6 +404,8 @@ comm_poll(int msec) } if (commCheckICPIncoming) comm_poll_icp_incoming(); + if (commCheckDNSIncoming) + comm_poll_dns_incoming(); if (commCheckHTTPIncoming) comm_poll_http_incoming(); } @@ -376,6 +418,8 @@ comm_poll(int msec) } if (commCheckICPIncoming) comm_poll_icp_incoming(); + if (commCheckDNSIncoming) + comm_poll_dns_incoming(); if (commCheckHTTPIncoming) comm_poll_http_incoming(); } @@ -406,6 +450,8 @@ comm_poll(int msec) } if (callicp) comm_poll_icp_incoming(); + if (calldns) + comm_poll_dns_incoming(); if (callhttp) comm_poll_http_incoming(); #if !ALARM_UPDATES_TIME @@ -502,6 +548,27 @@ comm_select_icp_incoming(void) statHistCount(&Counter.comm_icp_incoming, nevents); } +static void +comm_select_dns_incoming(void) +{ + int nfds = 0; + int fds[2]; + int nevents; + dns_io_events = 0; + if (DnsSocket < 0) + return; + fds[nfds++] = DnsSocket; + nevents = comm_check_incoming_select_handlers(nfds, fds); + incoming_dns_interval += Config.comm_incoming.dns_average - nevents; + if (incoming_dns_interval < 0) + incoming_dns_interval = 0; + if (incoming_dns_interval > MAX_INCOMING_INTERVAL) + incoming_dns_interval = MAX_INCOMING_INTERVAL; + if (nevents > INCOMING_DNS_MAX) + nevents = INCOMING_DNS_MAX; + statHistCount(&Counter.comm_dns_incoming, nevents); +} + static void comm_select_http_incoming(void) { @@ -540,6 +607,7 @@ comm_select(int msec) int maxfd; int num; int callicp = 0, callhttp = 0; + int calldns = 0; int maxindex; int k; int j; @@ -561,9 +629,11 @@ comm_select(int msec) #endif if (commCheckICPIncoming) comm_select_icp_incoming(); + if (commCheckDNSIncoming) + comm_select_dns_incoming(); if (commCheckHTTPIncoming) comm_select_http_incoming(); - callicp = callhttp = 0; + callicp = calldns = callhttp = 0; maxfd = Biggest_FD + 1; xmemcpy(&readfds, &global_readfds, howmany(maxfd, FD_MASK_BITS) * FD_MASK_BYTES); @@ -653,6 +723,10 @@ comm_select(int msec) callicp = 1; continue; } + if (fdIsDns(fd)) { + calldns = 1; + continue; + } if (fdIsHttp(fd)) { callhttp = 1; continue; @@ -668,6 +742,8 @@ comm_select(int msec) } if (commCheckICPIncoming) comm_select_icp_incoming(); + if (commCheckDNSIncoming) + comm_select_dns_incoming(); if (commCheckHTTPIncoming) comm_select_http_incoming(); EBIT_CLR(tmask, k); /* this bit is done */ @@ -692,6 +768,10 @@ comm_select(int msec) callicp = 1; continue; } + if (fdIsDns(fd)) { + calldns = 1; + continue; + } if (fdIsHttp(fd)) { callhttp = 1; continue; @@ -707,6 +787,8 @@ comm_select(int msec) } if (commCheckICPIncoming) comm_select_icp_incoming(); + if (commCheckDNSIncoming) + comm_select_dns_incoming(); if (commCheckHTTPIncoming) comm_select_http_incoming(); EBIT_CLR(tmask, k); /* this bit is done */ @@ -716,6 +798,8 @@ comm_select(int msec) } if (callicp) comm_select_icp_incoming(); + if (calldns) + comm_select_dns_incoming(); if (callhttp) comm_select_http_incoming(); return COMM_OK; @@ -839,6 +923,8 @@ commIncomingStats(StoreEntry * sentry) StatCounters *f = &Counter; storeAppendPrintf(sentry, "Current incoming_icp_interval: %d\n", incoming_icp_interval >> INCOMING_FACTOR); + storeAppendPrintf(sentry, "Current incoming_dns_interval: %d\n", + incoming_dns_interval >> INCOMING_FACTOR); storeAppendPrintf(sentry, "Current incoming_http_interval: %d\n", incoming_http_interval >> INCOMING_FACTOR); storeAppendPrintf(sentry, "\n"); @@ -849,6 +935,12 @@ commIncomingStats(StoreEntry * sentry) storeAppendPrintf(sentry, "ICP Messages handled per comm_select_icp_incoming() call:\n"); #endif statHistDump(&f->comm_icp_incoming, sentry, statHistIntDumper); +#ifdef HAVE_POLL + storeAppendPrintf(sentry, "DNS Messages handled per comm_poll_dns_incoming() call:\n"); +#else + storeAppendPrintf(sentry, "DNS Messages handled per comm_select_dns_incoming() call:\n"); +#endif + statHistDump(&f->comm_dns_incoming, sentry, statHistIntDumper); #ifdef HAVE_POLL storeAppendPrintf(sentry, "HTTP Messages handled per comm_poll_http_incoming() call:\n"); #else diff --git a/src/defines.h b/src/defines.h index b4f17831b6..0edaf806f0 100644 --- a/src/defines.h +++ b/src/defines.h @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.72 1999/04/15 06:15:52 wessels Exp $ + * $Id: defines.h,v 1.73 1999/04/16 01:00:50 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -245,6 +245,10 @@ * Max number of ICP messages to receive per call to icpHandleUdp */ #define INCOMING_ICP_MAX 15 +/* + * Max number of DNS messages to receive per call to DNS read handler + */ +#define INCOMING_DNS_MAX 15 /* * Max number of HTTP connections to accept per call to httpAccept * and PER HTTP PORT diff --git a/src/dns_internal.cc b/src/dns_internal.cc index eba865b034..aeeb983ac5 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -1,6 +1,6 @@ /* - * $Id: dns_internal.cc,v 1.3 1999/04/15 06:03:48 wessels Exp $ + * $Id: dns_internal.cc,v 1.4 1999/04/16 01:00:51 wessels Exp $ * * DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c * AUTHOR: Duane Wessels @@ -51,7 +51,6 @@ struct _ns { static ns *nameservers = NULL; static int nns = 0; static int nns_alloc = 0; -static int domain_socket = -1; static dlink_list lru_list; static int event_queued = 0; @@ -135,8 +134,8 @@ idnsStats(StoreEntry * sentry) storeAppendPrintf(sentry, "------ ---- ----- --------\n"); for (n = lru_list.head; n; n = n->next) { q = n->data; - storeAppendPrintf(sentry, "%#06hx %4d %5d %8.3f\n", - q->id, q->sz, q->nsends, + storeAppendPrintf(sentry, "%#06x %4d %5d %8.3f\n", + (int) q->id, q->sz, q->nsends, tvSubDsec(q->start_t, current_time)); } storeAppendPrintf(sentry, "\nNameservers:\n"); @@ -154,12 +153,13 @@ static void idnsSendQuery(idns_query * q) { int x; - int ns = 0; + int ns; /* XXX Select nameserver */ assert(nns > 0); assert(q->lru.next == NULL); assert(q->lru.prev == NULL); - x = comm_udp_sendto(domain_socket, + ns = q->nsends % nns; + x = comm_udp_sendto(DnsSocket, &nameservers[ns].S, sizeof(nameservers[ns].S), q->buf, @@ -239,6 +239,7 @@ idnsGrokReply(const char *buf, size_t sz) static void idnsRead(int fd, void *data) { + int *N = data; ssize_t len; struct sockaddr_in from; socklen_t from_len; @@ -267,6 +268,7 @@ idnsRead(int fd, void *data) fd, xstrerror()); break; } + (*N)++; debug(78, 3) ("idnsRead: FD %d: received %d bytes from %s.\n", fd, len, @@ -305,17 +307,17 @@ void idnsInit(void) { static int init = 0; - if (domain_socket < 0) { - domain_socket = comm_open(SOCK_DGRAM, + if (DnsSocket < 0) { + DnsSocket = comm_open(SOCK_DGRAM, 0, Config.Addrs.udp_outgoing, 0, COMM_NONBLOCKING, "DNS Socket"); - if (domain_socket < 0) + if (DnsSocket < 0) fatal("Could not create a DNS socket"); - debug(78, 1) ("DNS Socket created on FD %d\n", domain_socket); - commSetSelect(domain_socket, COMM_SELECT_READ, idnsRead, NULL, 0); + debug(78, 1) ("DNS Socket created on FD %d\n", DnsSocket); + commSetSelect(DnsSocket, COMM_SELECT_READ, idnsRead, NULL, 0); } if (nns == 0) idnsParseResolvConf(); @@ -330,10 +332,10 @@ idnsInit(void) void idnsShutdown(void) { - if (domain_socket < 0) + if (DnsSocket < 0) return; - comm_close(domain_socket); - domain_socket = -1; + comm_close(DnsSocket); + DnsSocket = -1; } void diff --git a/src/globals.h b/src/globals.h index 0dfbabfa41..3bc7e354e1 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.77 1999/04/15 06:15:57 wessels Exp $ + * $Id: globals.h,v 1.78 1999/04/16 01:00:51 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -92,6 +92,7 @@ extern int opt_store_doublecheck; /* 0 */ extern int syslog_enable; /* 0 */ extern int theInIcpConnection; /* -1 */ extern int theOutIcpConnection; /* -1 */ +extern int DnsSocket; /* -1 */ #ifdef SQUID_SNMP extern int theInSnmpConnection; /* -1 */ extern int theOutSnmpConnection; /* -1 */ diff --git a/src/stat.cc b/src/stat.cc index ddbff7e0a0..35e2698ec2 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.312 1999/04/15 06:16:10 wessels Exp $ + * $Id: stat.cc,v 1.313 1999/04/16 01:00:52 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -936,6 +936,7 @@ statCountersInitSpecial(StatCounters * C) */ statHistEnumInit(&C->cd.on_xition_count, CacheDigestHashFuncCount); statHistEnumInit(&C->comm_icp_incoming, INCOMING_ICP_MAX); + statHistEnumInit(&C->comm_dns_incoming, INCOMING_DNS_MAX); statHistEnumInit(&C->comm_http_incoming, INCOMING_HTTP_MAX); statHistIntInit(&C->select_fds_hist, SQUID_MAXFD); } diff --git a/src/structs.h b/src/structs.h index 243a82e179..9c73bbf8b2 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.280 1999/04/15 06:16:13 wessels Exp $ + * $Id: structs.h,v 1.281 1999/04/16 01:00:54 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -424,8 +424,10 @@ struct _SquidConfig { #endif struct { int icp_average; + int dns_average; int http_average; int icp_min_poll; + int dns_min_poll; int http_min_poll; } comm_incoming; int max_open_disk_fds; @@ -1462,6 +1464,7 @@ struct _StatCounters { double cputime; struct timeval timestamp; StatHist comm_icp_incoming; + StatHist comm_dns_incoming; StatHist comm_http_incoming; StatHist select_fds_hist; struct {