Commit 1200bbaf authored by antirez's avatar antirez
Browse files

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.
parent 7af420e7
...@@ -1554,6 +1554,7 @@ void initServerConfig(void) { ...@@ -1554,6 +1554,7 @@ void initServerConfig(void) {
server.assert_line = 0; server.assert_line = 0;
server.bug_report_start = 0; server.bug_report_start = 0;
server.watchdog_period = 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 /* This function will try to raise the max number of open files accordingly to
...@@ -2071,6 +2072,9 @@ void preventCommandPropagation(redisClient *c) { ...@@ -2071,6 +2072,9 @@ void preventCommandPropagation(redisClient *c) {
/* Call() is the core of Redis execution of a command */ /* Call() is the core of Redis execution of a command */
void call(redisClient *c, int flags) { void call(redisClient *c, int flags) {
long long dirty, start, duration; 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; int client_old_flags = c->flags;
/* Sent the command to clients in MONITOR mode, only if the commands are /* Sent the command to clients in MONITOR mode, only if the commands are
...@@ -2086,9 +2090,9 @@ void call(redisClient *c, int flags) { ...@@ -2086,9 +2090,9 @@ void call(redisClient *c, int flags) {
c->flags &= ~(REDIS_FORCE_AOF|REDIS_FORCE_REPL); c->flags &= ~(REDIS_FORCE_AOF|REDIS_FORCE_REPL);
redisOpArrayInit(&server.also_propagate); redisOpArrayInit(&server.also_propagate);
dirty = server.dirty; dirty = server.dirty;
start = ustime(); if (get_duration) start = ustime();
c->cmd->proc(c); c->cmd->proc(c);
duration = ustime()-start; if (get_duration) duration = ustime()-start;
dirty = server.dirty-dirty; dirty = server.dirty-dirty;
if (dirty < 0) dirty = 0; if (dirty < 0) dirty = 0;
...@@ -2109,14 +2113,18 @@ void call(redisClient *c, int flags) { ...@@ -2109,14 +2113,18 @@ void call(redisClient *c, int flags) {
/* Log the command into the Slow log if needed, and populate the /* Log the command into the Slow log if needed, and populate the
* per-command statistics that we show in INFO commandstats. */ * 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) ? char *latency_event = (c->cmd->flags & REDIS_CMD_FAST) ?
"fast-command" : "command"; "fast-command" : "command";
latencyAddSampleIfNeeded(latency_event,duration/1000); latencyAddSampleIfNeeded(latency_event,duration/1000);
slowlogPushEntryIfNeeded(c->argv,c->argc,duration); slowlogPushEntryIfNeeded(c->argv,c->argc,duration);
} }
if (flags & REDIS_CALL_STATS) { if (flags & REDIS_CALL_STATS) {
c->cmd->microseconds += duration; if (server.use_cmd_time_accounting) c->cmd->microseconds += duration;
c->cmd->calls++; c->cmd->calls++;
} }
......
...@@ -732,6 +732,7 @@ struct redisServer { ...@@ -732,6 +732,7 @@ struct redisServer {
size_t resident_set_size; /* RSS sampled in serverCron(). */ size_t resident_set_size; /* RSS sampled in serverCron(). */
long long stat_net_input_bytes; /* Bytes read from network. */ long long stat_net_input_bytes; /* Bytes read from network. */
long long stat_net_output_bytes; /* Bytes written to 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 /* The following two are used to track instantaneous metrics, like
* number of operations per second, network traffic. */ * number of operations per second, network traffic. */
struct { struct {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment