summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-05-04 11:59:09 +0200
committerantirez <antirez@gmail.com>2015-05-04 12:05:56 +0200
commitcd05a665dc1dded3cfbc78ceaa5a5d00381f0ad7 (patch)
tree10ba0d80cde584c1c60b96cfc7732c3cfb7c8770
parent0b4ab6361edf8544ee0c3656966b453686b12610 (diff)
downloadredis-cd05a665dc1dded3cfbc78ceaa5a5d00381f0ad7.tar.gz
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.
-rw-r--r--src/multi.c4
-rw-r--r--src/scripting.c3
2 files changed, 6 insertions, 1 deletions
diff --git a/src/multi.c b/src/multi.c
index c82876456..05805310b 100644
--- a/src/multi.c
+++ b/src/multi.c
@@ -162,6 +162,10 @@ void execCommand(redisClient *c) {
c->mstate.commands[j].argc = c->argc;
c->mstate.commands[j].argv = c->argv;
c->mstate.commands[j].cmd = c->cmd;
+
+ /* From time to time, update the cached time so that if the transaction
+ * is huge, we'll have a chance to have more updated time info. */
+ if (j && j % 10000) updateCachedTime();
}
c->argv = orig_argv;
c->argc = orig_argc;
diff --git a/src/scripting.c b/src/scripting.c
index 46c0de9a2..3bad4d076 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -527,7 +527,8 @@ void luaMaskCountHook(lua_State *lua, lua_Debug *ar) {
REDIS_NOTUSED(ar);
REDIS_NOTUSED(lua);
- elapsed = mstime() - server.lua_time_start;
+ updateCachedTime();
+ elapsed = server.mstime - server.lua_time_start;
if (elapsed >= server.lua_time_limit && server.lua_timedout == 0) {
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);
server.lua_timedout = 1;