Attached is a patch in that effect. I have no empirical evidence this will improve things but I believe Fastly and others are doing it with good results.
On Sat, Mar 21, 2015 at 12:57 PM, Federico Schwindt <[email protected]> wrote: > Yeah, me not reading the code properly. > > So this could potentially help. > > On Wed, Mar 18, 2015 at 5:40 PM, Poul-Henning Kamp <[email protected]> > wrote: > >> -------- >> In message < >> cajv_h0bubvwppgboggqrk7+rgtjhj6rtxbf8kwqju3l5jvm...@mail.gmail.com> >> , Federico Schwindt writes: >> >> >My understanding and what I've read is that if you have multiple threads >> >accepting connections it'll will behave much better when running in >> >multiple cores which is pretty much everyone these days. >> > >> >Now looking at master, it looks we only have one acceptor per address and >> >not per pools. >> >> We have one thread per socket per pool. >> >> -- >> Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 >> [email protected] | TCP/IP since RFC 956 >> FreeBSD committer | BSD since 4.3-tahoe >> Never attribute to malice what can adequately be explained by >> incompetence. >> > >
From bc9ca6472c0d42fee3a28026089e8dd306abc207 Mon Sep 17 00:00:00 2001 From: "Federico G. Schwindt" <[email protected]> Date: Wed, 25 Mar 2015 14:59:49 +0000 Subject: [PATCH] Set SO_REUSEPORT in the socket if available This should improve behaviour in 3.9 and above kernels when calling accept() in multiple threads. --- configure.ac | 7 +++++++ lib/libvarnish/vtcp.c | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/configure.ac b/configure.ac index fafe5e4..e7696ad 100644 --- a/configure.ac +++ b/configure.ac @@ -471,6 +471,13 @@ if test "$ac_cv_have_tcp_keep" = yes; then fi LIBS="${save_LIBS}" +AC_CHECK_DECL([SO_REUSEPORT], + AC_DEFINE(HAVE_SO_REUSEPORT,1,[Define to 1 if you have SO_REUSEPORT]), + ,[ +#include <sys/types.h> +#include <sys/socket.h> + ]) + # Run-time directory VARNISH_STATE_DIR='${localstatedir}/varnish' AC_SUBST(VARNISH_STATE_DIR) diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c index a168c5f..accdc08 100644 --- a/lib/libvarnish/vtcp.c +++ b/lib/libvarnish/vtcp.c @@ -406,6 +406,17 @@ VTCP_bind(const struct suckaddr *sa, const char **errp) errno = e; return (-1); } +#ifdef HAVE_SO_REUSEPORT + val = 1; + if (setsockopt(sd, SOL_SOCKET, SO_REUSEPORT, &val, sizeof val) != 0) { + if (errp != NULL) + *errp = "setsockopt(SO_REUSEPORT, 1)"; + e = errno; + AZ(close(sd)); + errno = e; + return (-1); + } +#endif #ifdef IPV6_V6ONLY /* forcibly use separate sockets for IPv4 and IPv6 */ val = 1; -- 2.1.4
_______________________________________________ varnish-dev mailing list [email protected] https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev
