[Libevent-users] performance patch

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Feb 26 18:54:41 EST 2008


Tani Hosokawa пишет:
> Under high load, unless you build a dedicated acceptor thread you will 
> find that only allowing a listen backlog of 10 connections will cause 
> lots of attempted connections to simply be dropped if you have any 
> significant amount of processing to do per request.  The reason I put 
> 1024 in there is all implementations that I know of silently truncate 
> the backlog parameter to the system's maximum.  The reason I don't use 
> SOMAXCONN is some OS (older Solaris for sure) are incorrect for backward 
> compatibility reasons, and other OS are incorrect because the actual 
> setting is dynamically tunable via sysctl.
> 
> --- http.c.old  2008-02-26 12:30:45.000000000 -0800
> +++ http.c      2008-02-26 12:33:54.000000000 -0800
> @@ -2002,7 +2002,7 @@
>        if ((fd = bind_socket(address, port)) == -1)
>                return (-1);
> 
> -       if (listen(fd, 10) == -1) {
> +       if (listen(fd, 1024) == -1) {
>                event_warn("%s: listen", __func__);
>                EVUTIL_CLOSESOCKET(fd);
>                return (-1);
> 

As POSIX requires SOMAXCONN to be defined in sys/socket.h it is safe to 
use this value or define some constant in configure script, that detects 
  SOMAXCONN definition. Also in old Solaris systems backlog was limited 
to 5.


More information about the Libevent-users mailing list