diff --git a/redis.conf b/redis.conf index c7499ce1f..ab9ba337d 100644 --- a/redis.conf +++ b/redis.conf @@ -2200,6 +2200,26 @@ rdb-save-incremental-fsync yes # lfu-log-factor 10 # lfu-decay-time 1 + +# The maximum number of new client connections accepted per event-loop cycle. This configuration +# is set independently for TLS connections. +# +# By default, up to 10 new connection will be accepted per event-loop cycle for normal connections +# and up to 1 new connection per event-loop cycle for TLS connections. +# +# Adjusting this to a larger number can slightly improve efficiency for new connections +# at the risk of causing timeouts for regular commands on established connections. It is +# not advised to change this without ensuring that all clients have limited connection +# pools and exponential backoff in the case of command/connection timeouts. +# +# If your application is establishing a large number of new connections per second you should +# also consider tuning the value of tcp-backlog, which allows the kernel to buffer more +# pending connections before dropping or rejecting connections. +# +# max-new-connections-per-cycle 10 +# max-new-tls-connections-per-cycle 1 + + ########################### ACTIVE DEFRAGMENTATION ####################### # # What is active defragmentation? diff --git a/src/config.c b/src/config.c index b4e14eaf1..e5108558f 100644 --- a/src/config.c +++ b/src/config.c @@ -3198,6 +3198,8 @@ standardConfig static_configs[] = { createUIntConfig("maxclients", NULL, MODIFIABLE_CONFIG, 1, UINT_MAX, server.maxclients, 10000, INTEGER_CONFIG, NULL, updateMaxclients), createUIntConfig("unixsocketperm", NULL, IMMUTABLE_CONFIG, 0, 0777, server.unixsocketperm, 0, OCTAL_CONFIG, NULL, NULL), createUIntConfig("socket-mark-id", NULL, IMMUTABLE_CONFIG, 0, UINT_MAX, server.socket_mark_id, 0, INTEGER_CONFIG, NULL, NULL), + createUIntConfig("max-new-connections-per-cycle", NULL, MODIFIABLE_CONFIG, 1, 1000, server.max_new_conns_per_cycle, 10, INTEGER_CONFIG, NULL, NULL), + createUIntConfig("max-new-tls-connections-per-cycle", NULL, MODIFIABLE_CONFIG, 1, 1000, server.max_new_tls_conns_per_cycle, 1, INTEGER_CONFIG, NULL, NULL), #ifdef LOG_REQ_RES createUIntConfig("client-default-resp", NULL, IMMUTABLE_CONFIG | HIDDEN_CONFIG, 2, 3, server.client_default_resp, 2, INTEGER_CONFIG, NULL, NULL), #endif diff --git a/src/connection.h b/src/connection.h index d0a17ab4d..d0340d18f 100644 --- a/src/connection.h +++ b/src/connection.h @@ -40,7 +40,6 @@ #define CONN_INFO_LEN 32 #define CONN_ADDR_STR_LEN 128 /* Similar to INET6_ADDRSTRLEN, hoping to handle other protocols. */ -#define MAX_ACCEPTS_PER_CALL 1000 struct aeEventLoop; typedef struct connection connection; diff --git a/src/server.h b/src/server.h index a0ffdf746..437793b0e 100644 --- a/src/server.h +++ b/src/server.h @@ -1774,6 +1774,8 @@ struct redisServer { int latency_tracking_enabled; /* 1 if extended latency tracking is enabled, 0 otherwise. */ double *latency_tracking_info_percentiles; /* Extended latency tracking info output percentile list configuration. */ int latency_tracking_info_percentiles_len; + unsigned int max_new_tls_conns_per_cycle; /* The maximum number of tls connections that will be accepted during each invocation of the event loop. */ + unsigned int max_new_conns_per_cycle; /* The maximum number of tcp connections that will be accepted during each invocation of the event loop. */ /* AOF persistence */ int aof_enabled; /* AOF configuration */ int aof_state; /* AOF_(ON|OFF|WAIT_REWRITE) */ diff --git a/src/socket.c b/src/socket.c index dad8e93cc..61a2b9ea9 100644 --- a/src/socket.c +++ b/src/socket.c @@ -309,7 +309,8 @@ static void connSocketEventHandler(struct aeEventLoop *el, int fd, void *clientD } static void connSocketAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) { - int cport, cfd, max = MAX_ACCEPTS_PER_CALL; + int cport, cfd; + int max = server.max_new_conns_per_cycle; char cip[NET_IP_STR_LEN]; UNUSED(el); UNUSED(mask); diff --git a/src/tls.c b/src/tls.c index 7920b5f4e..d011c16ea 100644 --- a/src/tls.c +++ b/src/tls.c @@ -766,7 +766,8 @@ static void tlsEventHandler(struct aeEventLoop *el, int fd, void *clientData, in } static void tlsAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) { - int cport, cfd, max = MAX_ACCEPTS_PER_CALL; + int cport, cfd; + int max = server.max_new_tls_conns_per_cycle; char cip[NET_IP_STR_LEN]; UNUSED(el); UNUSED(mask); diff --git a/src/unix.c b/src/unix.c index bd146d024..eb5850765 100644 --- a/src/unix.c +++ b/src/unix.c @@ -92,7 +92,8 @@ static connection *connCreateAcceptedUnix(int fd, void *priv) { } static void connUnixAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) { - int cfd, max = MAX_ACCEPTS_PER_CALL; + int cfd; + int max = server.max_new_conns_per_cycle; UNUSED(el); UNUSED(mask); UNUSED(privdata);