对,就是 redis info
,结果里有个 instantaneous_ops_per_sec
指标,每秒执行命令数,这个是由 Redis 自己统计的。
但第一,这个值不是实时的,有延后性;第二,这个值由 Redis 自行维护,实际是 16 个周期的平均采样数据(即 1.6 秒的总数,除以 1.6),结果只能说是近似。毕竟强实时、高精度,必然会影响性能。
Redis 相关源码:
#define STATS_METRIC_SAMPLES 16 /* Number of samples per metric. */
#define STATS_METRIC_COMMAND 0 /* Number of commands executed. */
/* Return the mean of all the samples. */
long long getInstantaneousMetric(int metric) {
int j;
long long sum = 0;
for (j = 0; j < STATS_METRIC_SAMPLES; j++)
sum += server.inst_metric[metric].samples[j];
return sum / STATS_METRIC_SAMPLES;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…