summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-04-29 15:07:32 +0200
committerantirez <antirez@gmail.com>2015-04-29 15:08:57 +0200
commit1200bbafd18bb7ef9553fd4e95a8fd9b7575534c (patch)
tree335561fc0952ad24c1c29850c575adf44388c59c
parent7af420e78dea827fdc37d51da47b2b3b7e4bc63e (diff)
downloadredis-1200bbafd18bb7ef9553fd4e95a8fd9b7575534c.tar.gz
A way to disable time accounting in call().
This commit allows to avoid two mstime() calls inside the call() function, when the following conditions are true: 1. slowlog is disabled. 2. latency monitoring is disabled. 3. command time acconuting is disabled. Note that '3' was not configurable, this patch just disable it without really allowing the user to turn it on, since this is currently an experiment. If the commit will be merged into unstable, proper support to configure this parameter will be added. Related to issue #2552.
-rw-r--r--src/redis.c16
-rw-r--r--src/redis.h1
2 files changed, 13 insertions, 4 deletions
diff --git a/src/redis.c b/src/redis.c
index 787663e4a..2dfbea7b6 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -1554,6 +1554,7 @@ void initServerConfig(void) {
server.assert_line = 0;
server.bug_report_start = 0;
server.watchdog_period = 0;
+ server.use_cmd_time_accounting = 0; /* XXX: this should be configurable. */
}
/* This function will try to raise the max number of open files accordingly to
@@ -2071,6 +2072,9 @@ void preventCommandPropagation(redisClient *c) {
/* Call() is the core of Redis execution of a command */
void call(redisClient *c, int flags) {
long long dirty, start, duration;
+ int get_duration = server.latency_monitor_threshold != 0 ||
+ server.slowlog_log_slower_than != 0 ||
+ server.use_cmd_time_accounting != 0;
int client_old_flags = c->flags;
/* Sent the command to clients in MONITOR mode, only if the commands are
@@ -2086,9 +2090,9 @@ void call(redisClient *c, int flags) {
c->flags &= ~(REDIS_FORCE_AOF|REDIS_FORCE_REPL);
redisOpArrayInit(&server.also_propagate);
dirty = server.dirty;
- start = ustime();
+ if (get_duration) start = ustime();
c->cmd->proc(c);
- duration = ustime()-start;
+ if (get_duration) duration = ustime()-start;
dirty = server.dirty-dirty;
if (dirty < 0) dirty = 0;
@@ -2109,14 +2113,18 @@ void call(redisClient *c, int flags) {
/* Log the command into the Slow log if needed, and populate the
* per-command statistics that we show in INFO commandstats. */
- if (flags & REDIS_CALL_SLOWLOG && c->cmd->proc != execCommand) {
+ if (get_duration &&
+ flags & REDIS_CALL_SLOWLOG &&
+ c->cmd->proc != execCommand)
+ {
char *latency_event = (c->cmd->flags & REDIS_CMD_FAST) ?
"fast-command" : "command";
latencyAddSampleIfNeeded(latency_event,duration/1000);
slowlogPushEntryIfNeeded(c->argv,c->argc,duration);
}
+
if (flags & REDIS_CALL_STATS) {
- c->cmd->microseconds += duration;
+ if (server.use_cmd_time_accounting) c->cmd->microseconds += duration;
c->cmd->calls++;
}
diff --git a/src/redis.h b/src/redis.h
index 53f3967d7..c48f93347 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -732,6 +732,7 @@ struct redisServer {
size_t resident_set_size; /* RSS sampled in serverCron(). */
long long stat_net_input_bytes; /* Bytes read from network. */
long long stat_net_output_bytes; /* Bytes written to network. */
+ int use_cmd_time_accounting; /* commandstats time accounting. */
/* The following two are used to track instantaneous metrics, like
* number of operations per second, network traffic. */
struct {