Browse Source

[config] server.listen-backlog option (fixes #1825, #2116)

See doc/config/lighttpd.conf for explanation of listen() backlog queue

Additionally, mod_fastcgi and mod_scgi backend servers can now also be
configured with separate listen-backlog settings per server

x-ref:
  "add server.listen-backlog option instead of hard-coded value (128 * 8) for listen()"
  https://redmine.lighttpd.net/issues/2116
  "Don't disable backend when overloaded"
  https://redmine.lighttpd.net/issues/1825

github:
Closes #50
personal/stbuehler/mod-csrf-old
Glenn Strauss 6 years ago
parent
commit
71ed1912c7
  1. 1
      NEWS
  2. 29
      doc/config/lighttpd.conf
  3. 1
      src/base.h
  4. 8
      src/configfile.c
  5. 7
      src/mod_fastcgi.c
  6. 7
      src/mod_scgi.c
  7. 2
      src/network.c

1
NEWS

@ -79,6 +79,7 @@ NEWS
* [mod_redirect,mod_rewrite] short-circuit if blank replacement (fixes #2085)
* [mod_indexfile] save physical path to env (fixes #448, #892)
* [core] open fd when appending file to cq (fixes #2655)
* [config] server.listen-backlog option (fixes #1825, #2116)
- 1.4.39 - 2016-01-02
* [core] fix memset_s call (fixes #2698)

29
doc/config/lighttpd.conf

@ -206,6 +206,35 @@ server.network-backend = "sendfile"
##
server.max-fds = 2048
##
## listen-backlog is the size of the listen() backlog queue requested when
## the lighttpd server ask the kernel to listen() on the provided network
## address. Clients attempting to connect() to the server enter the listen()
## backlog queue and wait for the lighttpd server to accept() the connection.
##
## The out-of-box default on many operating systems is 128 and is identified
## as SOMAXCONN. This can be tuned on many operating systems. (On Linux,
## cat /proc/sys/net/core/somaxconn) Requesting a size larger than operating
## system limit will be silently reduced to the limit by the operating system.
##
## When there are too many connection attempts waiting for the server to
## accept() new connections, the listen backlog queue fills and the kernel
## rejects additional connection attempts. This can be useful as an
## indication to an upstream load balancer that the server is busy, and
## possibly overloaded. In that case, configure a smaller limit for
## server.listen-backlog. On the other hand, configure a larger limit to be
## able to handle bursts of new connections, but only do so up to an amount
## that the server can keep up with responding in a reasonable amount of
## time. Otherwise, clients may abandon the connection attempts and the
## server will waste resources servicing abandoned connections.
##
## It is best to leave this setting at its default unless you have modelled
## your traffic and tested that changing this benefits your traffic patterns.
##
## Default: 1024
##
#server.listen-backlog = 128
##
## Stat() call caching.
##

1
src/base.h

@ -294,6 +294,7 @@ typedef struct {
unsigned short etag_use_size;
unsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */
unsigned int max_request_size;
int listen_backlog;
unsigned short kbytes_per_second; /* connection kb/s limit */

8
src/configfile.c

@ -111,6 +111,7 @@ static int config_insert(server *srv) {
{ "ssl.empty-fragments", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 67 */
{ "server.upload-temp-file-size", NULL, T_CONFIG_INT, T_CONFIG_SCOPE_SERVER }, /* 68 */
{ "mimetype.xattr-name", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 69 */
{ "server.listen-backlog", NULL, T_CONFIG_INT, T_CONFIG_SCOPE_CONNECTION }, /* 70 */
{ "server.host",
"use server.bind instead",
@ -229,6 +230,7 @@ static int config_insert(server *srv) {
s->ssl_verifyclient_depth = 9;
s->ssl_verifyclient_export_cert = 0;
s->ssl_disable_client_renegotiation = 1;
s->listen_backlog = (0 == i ? 1024 : srv->config_storage[0]->listen_backlog);
/* all T_CONFIG_SCOPE_CONNECTION options */
cv[2].destination = s->errorfile_prefix;
@ -285,6 +287,7 @@ static int config_insert(server *srv) {
cv[65].destination = &(s->ssl_disable_client_renegotiation);
cv[66].destination = &(s->ssl_honor_cipher_order);
cv[67].destination = &(s->ssl_empty_fragments);
cv[70].destination = &(s->listen_backlog);
srv->config_storage[i] = s;
@ -355,6 +358,7 @@ int config_setup_connection(server *srv, connection *con) {
PATCH(range_requests);
PATCH(force_lowercase_filenames);
/*PATCH(listen_backlog);*//*(not necessary; used only at startup)*/
PATCH(ssl_enabled);
PATCH(ssl_pemfile);
@ -483,6 +487,10 @@ int config_patch_connection(server *srv, connection *con) {
PATCH(allow_http11);
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.force-lowercase-filenames"))) {
PATCH(force_lowercase_filenames);
#if 0 /*(not necessary; used only at startup)*/
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.listen-backlog"))) {
PATCH(listen_backlog);
#endif
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.kbytes-per-second"))) {
PATCH(global_kbytes_per_second);
PATCH(global_bytes_per_second_cnt);

7
src/mod_fastcgi.c

@ -250,6 +250,8 @@ typedef struct {
applications prefer SIGUSR1 while the
rest of the world would use SIGTERM
*sigh* */
int listen_backlog;
} fcgi_extension_host;
/*
@ -991,7 +993,7 @@ static int fcgi_spawn_connection(server *srv,
return -1;
}
if (-1 == listen(fcgi_fd, 1024)) {
if (-1 == listen(fcgi_fd, host->listen_backlog)) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"listen failed:", strerror(errno));
close(fcgi_fd);
@ -1288,6 +1290,7 @@ SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
{ "strip-request-uri", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 13 */
{ "kill-signal", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 14 */
{ "fix-root-scriptname", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 15 */
{ "listen-backlog", NULL, T_CONFIG_INT, T_CONFIG_SCOPE_CONNECTION }, /* 16 */
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
};
@ -1314,6 +1317,7 @@ SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
host->allow_xsendfile = 0; /* handle X-LIGHTTPD-send-file */
host->kill_signal = SIGTERM;
host->fix_root_path_name = 0;
host->listen_backlog = 1024;
fcv[0].destination = host->host;
fcv[1].destination = host->docroot;
@ -1333,6 +1337,7 @@ SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
fcv[13].destination = host->strip_request_uri;
fcv[14].destination = &(host->kill_signal);
fcv[15].destination = &(host->fix_root_path_name);
fcv[16].destination = &(host->listen_backlog);
if (0 != config_insert_values_internal(srv, da_host->value, fcv, T_CONFIG_SCOPE_CONNECTION)) {
goto error;

7
src/mod_scgi.c

@ -223,6 +223,8 @@ typedef struct {
only if a process is killed max_id waits for the process itself
to die and decrements its afterwards */
int listen_backlog;
} scgi_extension_host;
/*
@ -786,7 +788,7 @@ static int scgi_spawn_connection(server *srv,
return -1;
}
if (-1 == listen(scgi_fd, 1024)) {
if (-1 == listen(scgi_fd, host->listen_backlog)) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"listen failed:", strerror(errno));
close(scgi_fd);
@ -1053,6 +1055,7 @@ SETDEFAULTS_FUNC(mod_scgi_set_defaults) {
{ "bin-environment", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 11 */
{ "bin-copy-environment", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 12 */
{ "fix-root-scriptname", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 13 */
{ "listen-backlog", NULL, T_CONFIG_INT, T_CONFIG_SCOPE_CONNECTION }, /* 14 */
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
@ -1076,6 +1079,7 @@ SETDEFAULTS_FUNC(mod_scgi_set_defaults) {
df->idle_timeout = 60;
df->disable_time = 60;
df->fix_root_path_name = 0;
df->listen_backlog = 1024;
fcv[0].destination = df->host;
fcv[1].destination = df->docroot;
@ -1093,6 +1097,7 @@ SETDEFAULTS_FUNC(mod_scgi_set_defaults) {
fcv[11].destination = df->bin_env;
fcv[12].destination = df->bin_env_copy;
fcv[13].destination = &(df->fix_root_path_name);
fcv[14].destination = &(df->listen_backlog);
if (0 != config_insert_values_internal(srv, da_host->value, fcv, T_CONFIG_SCOPE_CONNECTION)) {

2
src/network.c

@ -436,7 +436,7 @@ static int network_server_init(server *srv, buffer *host_token, specific_config
goto error_free_socket;
}
if (-1 == listen(srv_socket->fd, 128 * 8)) {
if (-1 == listen(srv_socket->fd, s->listen_backlog)) {
log_error_write(srv, __FILE__, __LINE__, "ss", "listen failed: ", strerror(errno));
goto error_free_socket;
}

Loading…
Cancel
Save