From 9398671804e50c822f9db544a62408ec95211aff Mon Sep 17 00:00:00 2001 From: tezc Date: Sun, 28 Aug 2022 00:27:58 +0300 Subject: [PATCH] Avoid unnecessary system calls in redisAsyncCommand() --- async.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/async.c b/async.c index ae097df0b..fc5d5fc55 100644 --- a/async.c +++ b/async.c @@ -950,10 +950,17 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void } } + /* We know the previous write was partial if there is data in the output + * buffer. So, we wait for a write event to write to the socket. Otherwise, + * we can directly write data to the socket. */ + int pending_write = (sdslen(c->obuf) != 0); + __redisAppendCommand(c,cmd,len); - /* Always schedule a write when the write buffer is non-empty */ - _EL_ADD_WRITE(ac); + if (!pending_write) + redisAsyncWrite(ac); + else + _EL_ADD_WRITE(ac); return REDIS_OK; oom: