Skip to content

Commit 0d2522f

Browse files
committed
Fix incorrect latency of multiple key command
1 parent 56ff605 commit 0d2522f

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/command.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,6 @@ void cmd_mark_fail(struct command *cmd, const char *reason)
11181118
void cmd_stats(struct command *cmd, int64_t end_time)
11191119
{
11201120
struct context *ctx = cmd->ctx;
1121-
struct command *last, *first;
11221121
long long latency;
11231122

11241123
ATOMIC_INC(ctx->stats.completed_commands, 1);
@@ -1128,13 +1127,7 @@ void cmd_stats(struct command *cmd, int64_t end_time)
11281127
ATOMIC_INC(ctx->stats.total_latency, latency);
11291128
ATOMIC_SET(ctx->last_command_latency, latency);
11301129

1131-
if (!STAILQ_EMPTY(&cmd->sub_cmds)) {
1132-
first = STAILQ_FIRST(&cmd->sub_cmds);
1133-
last = STAILQ_LAST(&cmd->sub_cmds, command, sub_cmd_next);
1134-
latency = last->rep_time[1] - first->rep_time[0];
1135-
} else {
1136-
latency = cmd->rep_time[1] - cmd->rep_time[0];
1137-
}
1130+
latency = cmd->rep_time[1] - cmd->rep_time[0];
11381131

11391132
if (slowlog_need_log(cmd, latency)) {
11401133
if (slowlog_statsd_enabled()) {

src/server.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ void server_make_iov(struct conn_info *info)
6464
cmd_iov_add(&info->iov, (void*)req_ask, strlen(req_ask), NULL);
6565
}
6666
cmd->rep_time[0] = t;
67+
if (cmd->parent) {
68+
int64_t parent_rep_start_time = cmd->parent->rep_time[0];
69+
if (parent_rep_start_time == 0 || parent_rep_start_time > t)
70+
cmd->parent->rep_time[0] = t;
71+
}
6772

6873
if (cmd->prefix != NULL) {
6974
cmd_iov_add(&info->iov, (void*)cmd->prefix, strlen(cmd->prefix), NULL);
@@ -234,6 +239,11 @@ int server_read(struct connection *server)
234239
status = server_read_reply(server, cmd);
235240

236241
cmd->rep_time[1] = now;
242+
if (cmd->parent) {
243+
int64_t parent_rep_end_time = cmd->parent->rep_time[1];
244+
if (parent_rep_end_time == 0 || parent_rep_end_time < now)
245+
cmd->parent->rep_time[1] = now;
246+
}
237247

238248
switch (status) {
239249
case CORVUS_ASKING:

0 commit comments

Comments
 (0)