diff options
author | 杨博东 <yangbodong22011@gmail.com> | 2020-08-11 13:18:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-11 08:18:09 +0300 |
commit | 229327ad8be5cd87ead56884228dfb08b6017c45 (patch) | |
tree | d7887540494ca2b76e9a0e97043b2196817ec296 /src/blocked.c | |
parent | efe92ee5462f65b6a4dabb3d578a31bedcad2f33 (diff) | |
download | redis-229327ad8be5cd87ead56884228dfb08b6017c45.tar.gz |
Avoid redundant calls to signalKeyAsReady (#7625)
signalKeyAsReady has some overhead (namely dictFind) so we should
only call it when there are clients blocked on the relevant type (BLOCKED_*)
Diffstat (limited to 'src/blocked.c')
-rw-r--r-- | src/blocked.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/blocked.c b/src/blocked.c index 92f1cee65..c3884fbdf 100644 --- a/src/blocked.c +++ b/src/blocked.c @@ -634,6 +634,16 @@ void unblockClientWaitingData(client *c) { } } +static int getBlockedTypeByType(int type) { + switch (type) { + case OBJ_LIST: return BLOCKED_LIST; + case OBJ_ZSET: return BLOCKED_ZSET; + case OBJ_MODULE: return BLOCKED_MODULE; + case OBJ_STREAM: return BLOCKED_STREAM; + default: return BLOCKED_NONE; + } +} + /* If the specified key has clients blocked waiting for list pushes, this * function will put the key reference into the server.ready_keys list. * Note that db->ready_keys is a hash table that allows us to avoid putting @@ -641,9 +651,14 @@ void unblockClientWaitingData(client *c) { * made by a script or in the context of MULTI/EXEC. * * The list will be finally processed by handleClientsBlockedOnKeys() */ -void signalKeyAsReady(redisDb *db, robj *key) { +void signalKeyAsReady(redisDb *db, robj *key, int type) { readyList *rl; + /* If no clients are blocked on this type, just return */ + int btype = getBlockedTypeByType(type); + if (btype == BLOCKED_NONE || !server.blocked_clients_by_type[btype]) + return; + /* No clients blocking for this key? No need to queue it. */ if (dictFind(db->blocking_keys,key) == NULL) return; @@ -664,4 +679,3 @@ void signalKeyAsReady(redisDb *db, robj *key) { serverAssert(dictAdd(db->ready_keys,key,NULL) == DICT_OK); } - |