summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2017-12-05 15:51:15 +0100
committerGitHub <noreply@github.com>2017-12-05 15:51:15 +0100
commit03cfc8bf3ad3a172bd5c7f5a02ad7757c0c3f96d (patch)
tree959f852a3e792f02a1636b9dcf65e58dcdf9c30d
parentc56fbb246c720eec8a7c6434e51b681a3e11a1c8 (diff)
parent43be967690d7b778cf829540b504a9662177511d (diff)
downloadredis-03cfc8bf3ad3a172bd5c7f5a02ad7757c0c3f96d.tar.gz
Merge pull request #4497 from soloestoy/optimize-unlink-client
networking: optimize unlinkClient() in freeClient()
-rw-r--r--src/networking.c14
-rw-r--r--src/replication.c1
-rw-r--r--src/server.h1
3 files changed, 12 insertions, 4 deletions
diff --git a/src/networking.c b/src/networking.c
index f0bdacfae..b1235ed41 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -136,7 +136,12 @@ client *createClient(int fd) {
c->peerid = NULL;
listSetFreeMethod(c->pubsub_patterns,decrRefCountVoid);
listSetMatchMethod(c->pubsub_patterns,listMatchObjects);
- if (fd != -1) listAddNodeTail(server.clients,c);
+ if (fd != -1) {
+ listAddNodeTail(server.clients,c);
+ c->client_list_node = listLast(server.clients);
+ } else {
+ c->client_list_node = NULL;
+ }
initClientMultiState(c);
return c;
}
@@ -744,9 +749,10 @@ void unlinkClient(client *c) {
* fd is already set to -1. */
if (c->fd != -1) {
/* Remove from the list of active clients. */
- ln = listSearchKey(server.clients,c);
- serverAssert(ln != NULL);
- listDelNode(server.clients,ln);
+ if (c->client_list_node) {
+ listDelNode(server.clients,c->client_list_node);
+ c->client_list_node = NULL;
+ }
/* Unregister async I/O handlers and close the socket. */
aeDeleteFileEvent(server.el,c->fd,AE_READABLE);
diff --git a/src/replication.c b/src/replication.c
index cf4db3e3a..1207e060b 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -2206,6 +2206,7 @@ void replicationResurrectCachedMaster(int newfd) {
/* Re-add to the list of clients. */
listAddNodeTail(server.clients,server.master);
+ server.master->client_list_node = listLast(server.clients);
if (aeCreateFileEvent(server.el, newfd, AE_READABLE,
readQueryFromClient, server.master)) {
serverLog(LL_WARNING,"Error resurrecting the cached master, impossible to add the readable handler: %s", strerror(errno));
diff --git a/src/server.h b/src/server.h
index 16e912564..afae8c58c 100644
--- a/src/server.h
+++ b/src/server.h
@@ -733,6 +733,7 @@ typedef struct client {
dict *pubsub_channels; /* channels a client is interested in (SUBSCRIBE) */
list *pubsub_patterns; /* patterns a client is interested in (SUBSCRIBE) */
sds peerid; /* Cached peer ID. */
+ listNode *client_list_node; /* list node in client list */
/* Response buffer */
int bufpos;