From 1fbbdcb083791dc5a6a8b64884735911b199ccfd Mon Sep 17 00:00:00 2001 From: hno <> Date: Fri, 28 Sep 2001 03:59:22 +0000 Subject: [PATCH] Resurrected Duanes old sleep_after_fork patch. This needed or we will race with ourselves for swap space when restarting helpers. The hello test is not really sufficient, we must also wait for the child to actually exec() before forking again. In the event that we are starting many helpers who uses CPU it is not too unlikely to see a newly started child to be context switched before exec(). Anyway, default configuration does nothing. To activate this one must configure sleep_after_fork in squid.conf so it is a quite harmless patch, and if it helps some people, fine. --- src/cf.data.pre | 18 +++++++++++++++++- src/ipc.cc | 9 ++++++++- src/structs.h | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/cf.data.pre b/src/cf.data.pre index 0cbff10cdb..0fe5aafd2e 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.224 2001/08/19 16:33:17 wessels Exp $ +# $Id: cf.data.pre,v 1.225 2001/09/27 21:59:22 hno Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -3656,5 +3656,21 @@ DOC_START objects not intended for caching to get cached. DOC_END +NAME: sleep_after_fork +COMMENT: (microseconds) +TYPE: int +LOC: Config.sleep_after_fork +DEFAULT: 0 +DOC_START + When this is set to a non-zero value, the main Squid process + sleeps the specified number of microseconds after a fork() + system call. This sleep may help the situation where your + system reports fork() failures due to lack of (virtual) + memory. Note, however, that if you have a lot of child + processes, then these sleep delays will add up and your + Squid will not service requests for some amount of time + until all the child processes have been started. +DOC_END + EOF diff --git a/src/ipc.cc b/src/ipc.cc index 3f08510e32..5be079ca8f 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -1,6 +1,6 @@ /* - * $Id: ipc.cc,v 1.23 2001/08/29 14:57:35 robertc Exp $ + * $Id: ipc.cc,v 1.24 2001/09/27 21:59:22 hno Exp $ * * DEBUG: section 54 Interprocess Communication * AUTHOR: Duane Wessels @@ -204,6 +204,13 @@ ipcCreate(int type, const char *prog, char *const args[], const char *name, int *wfd = pwfd; fd_table[prfd].flags.ipc = 1; fd_table[pwfd].flags.ipc = 1; + if (Config.sleep_after_fork) { + /* XXX emulation of usleep() */ + struct timeval sl; + sl.tv_sec = Config.sleep_after_fork / 1000000; + sl.tv_usec = Config.sleep_after_fork % 1000000; + select(0, NULL, NULL, NULL, &sl); + } return pid; } /* child */ diff --git a/src/structs.h b/src/structs.h index 74a1f325cc..9fc8a0a677 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.399 2001/09/07 18:02:48 adrian Exp $ + * $Id: structs.h,v 1.400 2001/09/27 21:59:22 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -664,6 +664,7 @@ struct _SquidConfig { size_t high_memory; } warnings; char *store_dir_select_algorithm; + int sleep_after_fork; /* microseconds */ }; struct _SquidConfig2 { -- 2.47.2