]> err.no Git - varnish/commitdiff
Sleep for a bit if accept(2) returns EMFILE
authortfheen <tfheen@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 7 Oct 2008 09:46:24 +0000 (09:46 +0000)
committertfheen <tfheen@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 7 Oct 2008 09:46:24 +0000 (09:46 +0000)
Hopefully, this will mitigate pile-ups somewhat and prevent us from
running out of file descriptors, at least as quickly.

See #330.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3261 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/mgt_param.c

index e4fa352c8e292b0b97b1c34027d9fbe1264be11d..cf47872a185d598af7c0ad09c68e5bced54bc3c1 100644 (file)
@@ -221,10 +221,20 @@ vca_acct(void *arg)
                        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;
                        }
index 80c1c3a7c2678b9f0c62a316f492778bc33f36c8..9cf61337293b895d1859d439a092396c92ba8558 100644 (file)
@@ -179,6 +179,10 @@ struct params {
 
        /* 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;
index 3a080886b2a92557f931ec967a6f9c866923a0c3..fab995ddb3962419745d69ecc24e49c4d2d730ae 100644 (file)
@@ -747,6 +747,12 @@ static const struct parspec parspec[] = {
                "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.",