Skip to content

Commit da58926

Browse files
committed
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 redis#2552.
1 parent 081a0c9 commit da58926

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/redis.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ void initServerConfig(void) {
14531453
server.assert_line = 0;
14541454
server.bug_report_start = 0;
14551455
server.watchdog_period = 0;
1456+
server.use_cmd_time_accounting = 0; /* XXX: this should be configurable. */
14561457
}
14571458

14581459
/* This function will try to raise the max number of open files accordingly to
@@ -1932,6 +1933,9 @@ void forceCommandPropagation(redisClient *c, int flags) {
19321933
/* Call() is the core of Redis execution of a command */
19331934
void call(redisClient *c, int flags) {
19341935
long long dirty, start, duration;
1936+
int get_duration = server.latency_monitor_threshold != 0 ||
1937+
server.slowlog_log_slower_than != 0 ||
1938+
server.use_cmd_time_accounting != 0;
19351939
int client_old_flags = c->flags;
19361940

19371941
/* Sent the command to clients in MONITOR mode, only if the commands are
@@ -1947,9 +1951,9 @@ void call(redisClient *c, int flags) {
19471951
c->flags &= ~(REDIS_FORCE_AOF|REDIS_FORCE_REPL);
19481952
redisOpArrayInit(&server.also_propagate);
19491953
dirty = server.dirty;
1950-
start = ustime();
1954+
if (get_duration) start = ustime();
19511955
c->cmd->proc(c);
1952-
duration = ustime()-start;
1956+
if (get_duration) duration = ustime()-start;
19531957
dirty = server.dirty-dirty;
19541958
if (dirty < 0) dirty = 0;
19551959

@@ -1970,14 +1974,18 @@ void call(redisClient *c, int flags) {
19701974

19711975
/* Log the command into the Slow log if needed, and populate the
19721976
* per-command statistics that we show in INFO commandstats. */
1973-
if (flags & REDIS_CALL_SLOWLOG && c->cmd->proc != execCommand) {
1977+
if (get_duration &&
1978+
flags & REDIS_CALL_SLOWLOG &&
1979+
c->cmd->proc != execCommand)
1980+
{
19741981
char *latency_event = (c->cmd->flags & REDIS_CMD_FAST) ?
19751982
"fast-command" : "command";
19761983
latencyAddSampleIfNeeded(latency_event,duration/1000);
19771984
slowlogPushEntryIfNeeded(c->argv,c->argc,duration);
19781985
}
1986+
19791987
if (flags & REDIS_CALL_STATS) {
1980-
c->cmd->microseconds += duration;
1988+
if (server.use_cmd_time_accounting) c->cmd->microseconds += duration;
19811989
c->cmd->calls++;
19821990
}
19831991

src/redis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ struct redisServer {
666666
size_t resident_set_size; /* RSS sampled in serverCron(). */
667667
long long stat_net_input_bytes; /* Bytes read from network. */
668668
long long stat_net_output_bytes; /* Bytes written to network. */
669+
int use_cmd_time_accounting; /* commandstats time accounting. */
669670
/* The following two are used to track instantaneous metrics, like
670671
* number of operations per second, network traffic. */
671672
struct {

0 commit comments

Comments
 (0)