Mailing List Archive

r3261 - trunk/varnish-cache/bin/varnishd
Author: tfheen
Date: 2008-10-07 11:46:24 +0200 (Tue, 07 Oct 2008)
New Revision: 3261

Modified:
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt_param.c
Log:
Sleep for a bit if accept(2) returns EMFILE

Hopefully, this will mitigate pile-ups somewhat and prevent us from
running out of file descriptors, at least as quickly.

See #330.


Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-10-07 09:46:21 UTC (rev 3260)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-10-07 09:46:24 UTC (rev 3261)
@@ -221,10 +221,20 @@
addr = (void*)&addr_s;
i = accept(ls->sock, addr, &l);
if (i < 0) {
- if (errno != EAGAIN && errno != ECONNABORTED) {
+ switch (errno) {
+ case EAGAIN:
+ case ECONNABORTED:
+ break;
+ case EMFILE:
VSL(SLT_Debug, ls->sock,
- "Accept failed errno=%d", errno);
+ "Too many open files when accept(2)ing. Sleeping.");
+ TIM_sleep(params->accept_fd_holdoff * 1000.0);
+ break;
+ default:
+ VSL(SLT_Debug, ls->sock,
+ "Accept failed: %s", strerror(errno));
/* XXX: stats ? */
+ break;
}
continue;
}

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2008-10-07 09:46:21 UTC (rev 3260)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-10-07 09:46:24 UTC (rev 3261)
@@ -179,6 +179,10 @@

/* Acceptable clockskew with backends */
unsigned clock_skew;
+
+ /* Amount of time to sleep when running out of file
+ descriptors. In msecs */
+ unsigned accept_fd_holdoff;
};

extern volatile struct params *params;

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-10-07 09:46:21 UTC (rev 3260)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-10-07 09:46:24 UTC (rev 3261)
@@ -747,6 +747,12 @@
"VCL can override this default value for each backend.",
0,
"400", "ms" },
+ { "accept_fd_holdoff", tweak_timeout,
+ &master.accept_fd_holdoff, 0, 3600*1000,
+ "If we run out of file descriptors, the accept thread will "
+ "sleep. This parameter control for how long it will sleep.",
+ EXPERIMENTAL,
+ "50", "ms" },
{ "clock_skew", tweak_uint, &master.clock_skew, 0, UINT_MAX,
"How much clockskew we are willing to accept between the "
"backend and our own clock.",