mirror of
https://github.com/fluencelabs/redis
synced 2025-06-22 13:31:32 +00:00
Add support for listen(2) backlog definition
In high RPS environments, the default listen backlog is not sufficient, so giving users the power to configure it is the right approach, especially since it requires only minor modifications to the code.
This commit is contained in:
committed by
antirez
parent
f0652c37a5
commit
8dda9dbef0
11
src/redis.c
11
src/redis.c
@ -1266,6 +1266,7 @@ void initServerConfig() {
|
||||
server.runid[REDIS_RUN_ID_SIZE] = '\0';
|
||||
server.arch_bits = (sizeof(long) == 8) ? 64 : 32;
|
||||
server.port = REDIS_SERVERPORT;
|
||||
server.backlog = REDIS_BACKLOG;
|
||||
server.bindaddr_count = 0;
|
||||
server.unixsocket = NULL;
|
||||
server.unixsocketperm = REDIS_DEFAULT_UNIX_SOCKET_PERM;
|
||||
@ -1469,9 +1470,9 @@ int listenToPort(int port, int *fds, int *count) {
|
||||
if (server.bindaddr[j] == NULL) {
|
||||
/* Bind * for both IPv6 and IPv4, we enter here only if
|
||||
* server.bindaddr_count == 0. */
|
||||
fds[*count] = anetTcp6Server(server.neterr,port,NULL);
|
||||
fds[*count] = anetTcp6Server(server.neterr,port,NULL, server.backlog);
|
||||
if (fds[*count] != ANET_ERR) (*count)++;
|
||||
fds[*count] = anetTcpServer(server.neterr,port,NULL);
|
||||
fds[*count] = anetTcpServer(server.neterr,port,NULL, server.backlog);
|
||||
if (fds[*count] != ANET_ERR) (*count)++;
|
||||
/* Exit the loop if we were able to bind * on IPv4 or IPv6,
|
||||
* otherwise fds[*count] will be ANET_ERR and we'll print an
|
||||
@ -1479,10 +1480,10 @@ int listenToPort(int port, int *fds, int *count) {
|
||||
if (*count) break;
|
||||
} else if (strchr(server.bindaddr[j],':')) {
|
||||
/* Bind IPv6 address. */
|
||||
fds[*count] = anetTcp6Server(server.neterr,port,server.bindaddr[j]);
|
||||
fds[*count] = anetTcp6Server(server.neterr,port,server.bindaddr[j], server.backlog);
|
||||
} else {
|
||||
/* Bind IPv4 address. */
|
||||
fds[*count] = anetTcpServer(server.neterr,port,server.bindaddr[j]);
|
||||
fds[*count] = anetTcpServer(server.neterr,port,server.bindaddr[j], server.backlog);
|
||||
}
|
||||
if (fds[*count] == ANET_ERR) {
|
||||
redisLog(REDIS_WARNING,
|
||||
@ -1530,7 +1531,7 @@ void initServer() {
|
||||
/* Open the listening Unix domain socket. */
|
||||
if (server.unixsocket != NULL) {
|
||||
unlink(server.unixsocket); /* don't care if this fails */
|
||||
server.sofd = anetUnixServer(server.neterr,server.unixsocket,server.unixsocketperm);
|
||||
server.sofd = anetUnixServer(server.neterr,server.unixsocket,server.unixsocketperm, server.backlog);
|
||||
if (server.sofd == ANET_ERR) {
|
||||
redisLog(REDIS_WARNING, "Opening socket: %s", server.neterr);
|
||||
exit(1);
|
||||
|
Reference in New Issue
Block a user