storage: collect flow statistics in batch_get_commands
@@ -331,6 +331,8 @@ impl<E: Engine, L: LockManager> Storage<E, L> {
.map_err(Error::from),
);
}
+ metrics::tls_collect_scan_details(CMD, &statistics);
+ metrics::tls_collect_read_flow(ctx.get_region_id(), &statistics);
SCHED_PROCESSING_READ_HISTOGRAM_STATIC
.get(CMD)
.observe(begin_instant.elapsed_secs());
@@ -705,10 +707,23 @@ impl<E: Engine, L: LockManager> Storage<E, L> {
let cf = Self::rawkv_cf(&cf)?;
let mut results = vec![];
+ // no scan_count for this kind of op.
+ let mut stats = Statistics::default();
// TODO: optimize using seek.
for get in gets {
- results.push(snapshot.get_cf(cf, &get.key).map_err(Error::from));
+ let key = &get.key;
+ let res = snapshot
+ .get_cf(cf, key)
+ .map(|v| {
+ stats.data.flow_stats.read_keys += 1;
+ stats.data.flow_stats.read_bytes += key.as_encoded().len()
+ + v.as_ref().map(|v| v.len()).unwrap_or(0);
+ v
+ })
+ .map_err(Error::from);
+ results.push(res);
}
+ metrics::tls_collect_read_flow(ctx.get_region_id(), &stats);
SCHED_PROCESSING_READ_HISTOGRAM_STATIC
.get(CMD)
.observe(begin_instant.elapsed_secs());
