From: wessels <> Date: Wed, 4 Jun 1997 13:00:31 +0000 (+0000) Subject: use alarm(3) for timing X-Git-Tag: SQUID_3_0_PRE1~4947 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=97c03d3cfe6697fc34ed5f7640f59f38cb145f94;p=thirdparty%2Fsquid.git use alarm(3) for timing --- diff --git a/src/comm.cc b/src/comm.cc index abc1d3e0ac..7a211a2d32 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.159 1997/06/04 06:15:48 wessels Exp $ + * $Id: comm.cc,v 1.160 1997/06/04 07:00:31 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -116,6 +116,7 @@ * 64 file descriptors free for disk-i/o and connections to remote servers */ int RESERVED_FD = 64; +int polledinc = 0; #define min(x,y) ((x)<(y)? (x) : (y)) #define max(a,b) ((a)>(b)? (a) : (b)) @@ -669,6 +670,7 @@ comm_poll_incoming(void) unsigned long i, nfds; int j; PF *hdl = NULL; + polledinc = 0; if (theInIcpConnection >= 0) fds[N++] = theInIcpConnection; if (theInIcpConnection != theOutIcpConnection) @@ -698,11 +700,11 @@ comm_poll_incoming(void) } if (!nfds) return; - if (poll(pfds, nfds, 0) < 1) + polledinc = poll(pfds, nfds, 0); + if (polledinc < 1) { + polledinc = 0; return; -#ifndef LESS_TIMING - getCurrentTime(); -#endif + } for (i = 0; i < nfds; i++) { int revents; if (((revents = pfds[i].revents) == 0) || ((fd = pfds[i].fd) == -1)) @@ -734,6 +736,7 @@ comm_select_incoming(void) int N = 0; int i = 0; PF *hdl = NULL; + polledinc = 0; FD_ZERO(&read_mask); FD_ZERO(&write_mask); for (i = 0; i < NHttpSockets; i++) { @@ -764,11 +767,11 @@ comm_select_incoming(void) } if (maxfd++ == 0) return; - if (select(maxfd, &read_mask, &write_mask, NULL, &zero_tv) < 1) + polledinc = select(maxfd, &read_mask, &write_mask, NULL, &zero_tv); + if (polledinc < 1) { + polledinc = 0; return; -#ifndef LESS_TIMING - getCurrentTime(); -#endif + } for (i = 0; i < N; i++) { fd = fds[i]; if (FD_ISSET(fd, &read_mask)) { @@ -813,17 +816,15 @@ comm_poll(time_t sec) unsigned long nfds; int num; static time_t last_timeout = 0; + static int lastinc = 0; int poll_time; static int incoming_counter = 0; time_t timeout; /* assume all process are very fast (less than 1 second). Call * time() only once */ - getCurrentTime(); /* use only 1 second granularity */ timeout = squid_curtime + sec; do { - if (sec > 60) - fatal_dump(NULL); if (shutdown_pending || reconfigure_pending) { serverConnectionsClose(); dnsShutdownServers(); @@ -866,7 +867,6 @@ comm_poll(time_t sec) poll_time = sec > 0 ? 1000 : 0; num = poll(pfds, nfds, poll_time); select_loops++; - getCurrentTime(); if (num >= 0) break; if (errno == EINTR) @@ -877,7 +877,6 @@ comm_poll(time_t sec) return COMM_ERROR; /* NOTREACHED */ } - getCurrentTime(); debug(5, num ? 5 : 8) ("comm_poll: %d sockets ready\n", num); /* Check timeout handlers ONCE each second. */ if (squid_curtime > last_timeout) { @@ -893,7 +892,7 @@ comm_poll(time_t sec) int revents; if (((revents = pfds[i].revents) == 0) || ((fd = pfds[i].fd) == -1)) continue; - if ((incoming_counter++ % 2) == 0) + if ((incoming_counter++ & (lastinc > 0 ? 1 : 7)) == 0) comm_poll_incoming(); if (fdIsHttpOrIcp(fd)) continue; @@ -939,9 +938,10 @@ comm_poll(time_t sec) fde->read_handler = NULL; fde->write_handler = NULL; } + lastinc = polledinc; } return COMM_OK; - } while (timeout > getCurrentTime()); + } while (timeout > squid_curtime); debug(5, 8) ("comm_poll: time out: %d.\n", squid_curtime); return COMM_TIMEOUT; } @@ -960,22 +960,20 @@ comm_select(time_t sec) int maxfd; int nfds; int num; + static int incoming_counter = 0; static time_t last_timeout = 0; struct timeval poll_time; + static int lastinc; time_t timeout; /* assume all process are very fast (less than 1 second). Call * time() only once */ - getCurrentTime(); /* use only 1 second granularity */ timeout = squid_curtime + sec; do { - if (sec > 60) - fatal_dump(NULL); FD_ZERO(&readfds); FD_ZERO(&writefds); - if (shutdown_pending || reconfigure_pending) { serverConnectionsClose(); dnsShutdownServers(); @@ -1016,7 +1014,6 @@ comm_select(time_t sec) poll_time.tv_usec = 0; num = select(maxfd, &readfds, &writefds, NULL, &poll_time); select_loops++; - getCurrentTime(); if (num >= 0) break; if (errno == EINTR) @@ -1048,12 +1045,8 @@ comm_select(time_t sec) for (fd = 0; fd < maxfd; fd++) { if (!FD_ISSET(fd, &readfds) && !FD_ISSET(fd, &writefds)) continue; - /* - * Admit more connections quickly until we hit the hard limit. - * Don't forget to keep the UDP acks coming and going. - */ - comm_select_incoming(); - + if ((incoming_counter++ & (lastinc > 0 ? 1 : 7) == 0) + comm_poll_incoming(); if (fdIsHttpOrIcp(fd)) continue; if (FD_ISSET(fd, &readfds)) { @@ -1062,7 +1055,6 @@ comm_select(time_t sec) hdl = fd_table[fd].read_handler; fd_table[fd].read_handler = 0; hdl(fd, fd_table[fd].read_data); - comm_select_incoming(); } } if (FD_ISSET(fd, &writefds)) { @@ -1071,13 +1063,12 @@ comm_select(time_t sec) hdl = fd_table[fd].write_handler; fd_table[fd].write_handler = 0; hdl(fd, fd_table[fd].write_data); - comm_select_incoming(); } } + lastinc = polledinc; } return COMM_OK; - } while (timeout > getCurrentTime()); - + } while (timeout > squid_curtime); debug(5, 8) ("comm_select: time out: %d.\n", squid_curtime); return COMM_TIMEOUT; } diff --git a/src/main.cc b/src/main.cc index a142b952b5..08df703cc6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,5 @@ /* - * $Id: main.cc,v 1.151 1997/06/04 06:16:01 wessels Exp $ + * $Id: main.cc,v 1.152 1997/06/04 07:00:31 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -157,6 +157,7 @@ static int malloc_debug_level = 0; static void rotate_logs _PARAMS((int)); static void reconfigure _PARAMS((int)); +static void time_tick _PARAMS((int)); static void mainInitialize _PARAMS((void)); static void mainReconfigure _PARAMS((void)); static void usage _PARAMS((void)); @@ -304,6 +305,17 @@ rotate_logs(int sig) #endif } +static void +time_tick(int sig) +{ + getCurrentTime(); + alarm(1); +#if !HAVE_SIGACTION + signal(sig, time_tick); +#endif +} + + static void reconfigure(int sig) { @@ -605,6 +617,8 @@ mainInitialize(void) squid_signal(SIGHUP, reconfigure, SA_RESTART); squid_signal(SIGTERM, shut_down, SA_NODEFER | SA_RESETHAND | SA_RESTART); squid_signal(SIGINT, shut_down, SA_NODEFER | SA_RESETHAND | SA_RESTART); + squid_signal(SIGALRM, time_tick, SA_RESTART); + alarm(1); debug(1, 0) ("Ready to serve requests.\n"); if (!configured_once) { diff --git a/src/net_db.cc b/src/net_db.cc index 31382a70ff..9fe4d93e85 100644 --- a/src/net_db.cc +++ b/src/net_db.cc @@ -1,6 +1,6 @@ /* - * $Id: net_db.cc,v 1.38 1997/06/04 06:16:04 wessels Exp $ + * $Id: net_db.cc,v 1.39 1997/06/04 07:00:32 wessels Exp $ * * DEBUG: section 37 Network Measurement Database * AUTHOR: Duane Wessels @@ -347,7 +347,6 @@ netdbSaveState(void *foo) count++; } fclose(fp); - getCurrentTime(); debug(37, 0) ("NETDB state saved; %d entries, %d msec\n", count, tvSubMsec(start, current_time)); eventAdd("netdbSaveState", netdbSaveState, NULL, 3617); @@ -407,7 +406,6 @@ netdbReloadState(void) } put_free_4k_page(buf); fclose(fp); - getCurrentTime(); debug(37, 0) ("NETDB state reloaded; %d entries, %d msec\n", count, tvSubMsec(start, current_time)); } diff --git a/src/stat.cc b/src/stat.cc index ee8de17ef3..ab4890b917 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.141 1997/06/04 06:16:10 wessels Exp $ + * $Id: stat.cc,v 1.142 1997/06/04 07:00:33 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -395,7 +395,6 @@ stat_objects_get(const cacheinfo * obj, StoreEntry * sentry, int vm_or_not) if (vm_or_not && mem == NULL) continue; if ((++N & 0xFF) == 0) { - getCurrentTime(); debug(18, 3) ("stat_objects_get: Processed %d objects...\n", N); } storeAppendPrintf(sentry, "{%s %dL %-25s %s %3d %2d %8d %s}\n", @@ -1084,9 +1083,6 @@ log_append(const cacheinfo * obj, client = fqdncache_gethostbyaddr(caddr, 0); if (client == NULL) client = inet_ntoa(caddr); - - getCurrentTime(); - if (!method) method = dash_str; if (!url) diff --git a/src/store.cc b/src/store.cc index ca29900c43..d07b0eed77 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.252 1997/06/04 06:16:11 wessels Exp $ + * $Id: store.cc,v 1.253 1997/06/04 07:00:34 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -1552,7 +1552,7 @@ storeRebuiltFromDisk(struct storeRebuildState *data) { time_t r; time_t stop; - stop = getCurrentTime(); + stop = squid_curtime; r = stop - data->start; debug(20, 1) ("Finished rebuilding storage from disk image.\n"); debug(20, 1) (" %7d Lines read from previous logfile.\n", data->linecount); @@ -1757,7 +1757,6 @@ storePurgeOld(void *unused) eventAdd("storePurgeOld", storePurgeOld, NULL, Config.cleanRate); for (e = storeGetFirst(); e; e = storeGetNext()) { if ((++n & 0xFF) == 0) { - getCurrentTime(); if (shutdown_pending || reconfigure_pending) break; } @@ -2023,8 +2022,6 @@ storeGetSwapSpace(int size) } else { swap_help = 0; } - - getCurrentTime(); /* we may have taken more than one second */ debug(20, 2) ("Removed %d objects\n", removed); return 0; } @@ -2437,7 +2434,7 @@ storeWriteCleanLogs(void) return 0; } debug(20, 1) ("storeWriteCleanLogs: Starting...\n"); - start = getCurrentTime(); + start = squid_curtime; fd = xcalloc(ncache_dirs, sizeof(int)); cur = xcalloc(ncache_dirs, sizeof(char *)); new = xcalloc(ncache_dirs, sizeof(char *)); @@ -2496,7 +2493,6 @@ storeWriteCleanLogs(void) continue; } if ((++n & 0x3FFF) == 0) { - getCurrentTime(); debug(20, 1) (" %7d lines written so far.\n", n); } } @@ -2511,7 +2507,7 @@ storeWriteCleanLogs(void) } storeDirCloseSwapLogs(); storeDirOpenSwapLogs(); - stop = getCurrentTime(); + stop = squid_curtime; r = stop - start; debug(20, 1) (" Finished. Wrote %d lines.\n", n); debug(20, 1) (" Took %d seconds (%6.1lf lines/sec).\n",