Skip to content

Commit 27db456

Browse files
committed
Update cached time during slow scripts & transactions
Commands may use cached time when the precision is not vital. It is a good idea to refresh it from time to time during the execution of long running scripts or transactions composed of quite a lot of commands.
1 parent e64d089 commit 27db456

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/multi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ void execCommand(redisClient *c) {
162162
c->mstate.commands[j].argc = c->argc;
163163
c->mstate.commands[j].argv = c->argv;
164164
c->mstate.commands[j].cmd = c->cmd;
165+
166+
/* From time to time, update the cached time so that if the transaction
167+
* is huge, we'll have a chance to have more updated time info. */
168+
if (j && j % 10000) updateCachedTime();
165169
}
166170
c->argv = orig_argv;
167171
c->argc = orig_argc;

src/scripting.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ void luaMaskCountHook(lua_State *lua, lua_Debug *ar) {
546546
REDIS_NOTUSED(ar);
547547
REDIS_NOTUSED(lua);
548548

549-
elapsed = mstime() - server.lua_time_start;
549+
updateCachedTime();
550+
elapsed = server.mstime - server.lua_time_start;
550551
if (elapsed >= server.lua_time_limit && server.lua_timedout == 0) {
551552
redisLog(REDIS_WARNING,"Lua slow script detected: still in execution after %lld milliseconds. You can try killing the script using the SCRIPT KILL command.",elapsed);
552553
server.lua_timedout = 1;

0 commit comments

Comments
 (0)