Skip to contentSkip to conversation

ceph: forward average read/write/metadata latency

PATCH In review Venky Shankar 3 participants 8 messages Feb 15, 2022 Ceph client

lore
Share & tools
lore
#0 lore raw

cover ceph: forward average read/write/metadata latency

Right now, cumulative read/write/metadata latencies are tracked and are periodically forwarded to the MDS. These meterics are not particularly useful. A much more useful metric is the average latency and standard deviation (stdev) which is what this series of patches aims to do.

The userspace (libcephfs+tool) changes are here::

          https://github.com/ceph/ceph/pull/41397

Note that the cumulative latencies are still forwarded to the MDS but the tool (cephfs-top) ignores it altogether.

Latency standard deviation is calculated in cephfs-top tool.

Venky Shankar (3):
ceph: track average r/w/m latency
ceph: include average/stdev r/w/m latency in mds metrics
ceph: use tracked average r/w/m latencies to display metrics in
debugfs

 fs/ceph/debugfs.c |  2 +-
 fs/ceph/metric.c  | 44 +++++++++++++++++++++++----------------
 fs/ceph/metric.h  | 52 +++++++++++++++++++++++++++++++++--------------
 3 files changed, 65 insertions(+), 33 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/3 ceph: track average r/w/m latency

Make the math a bit simpler to understand (should not effect execution speeds).

---
 fs/ceph/metric.c | 29 +++++++++++++++--------------
 fs/ceph/metric.h |  1 +
 2 files changed, 16 insertions(+), 14 deletions(-)
fs/ceph/metric.c +15 -14
index a9cd23561a0d..73e98d45442a 100644
@@ -250,6 +250,7 @@ int ceph_metric_init(struct ceph_client_metric *m)
 		metric->size_max = 0;
 		metric->total = 0;
 		metric->latency_sum = 0;
+		metric->latency_avg = 0;
 		metric->latency_sq_sum = 0;
 		metric->latency_min = KTIME_MAX;
 		metric->latency_max = 0;
@@ -307,20 +308,19 @@ void ceph_metric_destroy(struct ceph_client_metric *m)
 		max = new;			\
 }
 
-static inline void __update_stdev(ktime_t total, ktime_t lsum,
-				  ktime_t *sq_sump, ktime_t lat)
+static inline void __update_mean_and_stdev(ktime_t total, ktime_t *lavg,
+					   ktime_t *sq_sump, ktime_t lat)
 {
-	ktime_t avg, sq;
-
-	if (unlikely(total == 1))
-		return;
-
-	/* the sq is (lat - old_avg) * (lat - new_avg) */
-	avg = DIV64_U64_ROUND_CLOSEST((lsum - lat), (total - 1));
-	sq = lat - avg;
-	avg = DIV64_U64_ROUND_CLOSEST(lsum, total);
-	sq = sq * (lat - avg);
-	*sq_sump += sq;
+	ktime_t avg;
+
+	if (unlikely(total == 1)) {
+		*lavg = lat;
+	} else {
+		/* the sq is (lat - old_avg) * (lat - new_avg) */
+		avg = *lavg + div64_s64(lat - *lavg, total);
+		*sq_sump += (lat - *lavg)*(lat - avg);
+		*lavg = avg;
+	}
 }
 
 void ceph_update_metrics(struct ceph_metric *m,
@@ -339,6 +339,7 @@ void ceph_update_metrics(struct ceph_metric *m,
 	METRIC_UPDATE_MIN_MAX(m->size_min, m->size_max, size);
 	m->latency_sum += lat;
 	METRIC_UPDATE_MIN_MAX(m->latency_min, m->latency_max, lat);
-	__update_stdev(total, m->latency_sum, &m->latency_sq_sum, lat);
+	__update_mean_and_stdev(total, &m->latency_avg,	&m->latency_sq_sum,
+				lat);
 	spin_unlock(&m->lock);
 }
fs/ceph/metric.h +1 -0
index 5b2bb2897056..c47ba0074e49 100644
@@ -137,6 +137,7 @@ struct ceph_metric {
 	u64 size_min;
 	u64 size_max;
 	ktime_t latency_sum;
+	ktime_t latency_avg;
 	ktime_t latency_sq_sum;
 	ktime_t latency_min;
 	ktime_t latency_max;
Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/3 ceph: include average/stdev r/w/m latency in mds metrics

In reply to Venky Shankar

stdev is computed in cephfs-top tool - clients forward square of sums and IO count required to calculate stdev.

---
 fs/ceph/metric.c | 15 +++++++++++---
 fs/ceph/metric.h | 51 ++++++++++++++++++++++++++++++++++--------------
 2 files changed, 48 insertions(+), 18 deletions(-)
fs/ceph/metric.c +12 -3
index 73e98d45442a..5842da86c2bf 100644
@@ -65,31 +65,40 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	/* encode the read latency metric */
 	read = (struct ceph_metric_read_latency *)(cap + 1);
 	read->header.type = cpu_to_le32(CLIENT_METRIC_TYPE_READ_LATENCY);
-	read->header.ver = 1;
+	read->header.ver = 2;
 	read->header.compat = 1;
 	read->header.data_len = cpu_to_le32(sizeof(*read) - header_len);
 	sum = m->metric[METRIC_READ].latency_sum;
 	to_ceph_timespec(&read->lat, sum);
+	to_ceph_timespec(&read->avg, m->metric[METRIC_READ].latency_avg);
+	read->sq_sum = cpu_to_le64(m->metric[METRIC_READ].latency_sq_sum);
+	read->count = cpu_to_le64(m->metric[METRIC_READ].total);
 	items++;
 
 	/* encode the write latency metric */
 	write = (struct ceph_metric_write_latency *)(read + 1);
 	write->header.type = cpu_to_le32(CLIENT_METRIC_TYPE_WRITE_LATENCY);
-	write->header.ver = 1;
+	write->header.ver = 2;
 	write->header.compat = 1;
 	write->header.data_len = cpu_to_le32(sizeof(*write) - header_len);
 	sum = m->metric[METRIC_WRITE].latency_sum;
 	to_ceph_timespec(&write->lat, sum);
+	to_ceph_timespec(&write->avg, m->metric[METRIC_WRITE].latency_avg);
+	write->sq_sum = cpu_to_le64(m->metric[METRIC_WRITE].latency_sq_sum);
+	write->count = cpu_to_le64(m->metric[METRIC_WRITE].total);
 	items++;
 
 	/* encode the metadata latency metric */
 	meta = (struct ceph_metric_metadata_latency *)(write + 1);
 	meta->header.type = cpu_to_le32(CLIENT_METRIC_TYPE_METADATA_LATENCY);
-	meta->header.ver = 1;
+	meta->header.ver = 2;
 	meta->header.compat = 1;
 	meta->header.data_len = cpu_to_le32(sizeof(*meta) - header_len);
 	sum = m->metric[METRIC_METADATA].latency_sum;
 	to_ceph_timespec(&meta->lat, sum);
+	to_ceph_timespec(&meta->avg, m->metric[METRIC_METADATA].latency_avg);
+	meta->sq_sum = cpu_to_le64(m->metric[METRIC_METADATA].latency_sq_sum);
+	meta->count = cpu_to_le64(m->metric[METRIC_METADATA].total);
 	items++;
 
 	/* encode the dentry lease metric */
fs/ceph/metric.h +36 -15

81 lines not on this page · raw message

Signature · 1 line
2.27.0
#3 lore raw

PATCH 3/3 ceph: use tracked average r/w/m latencies to display metrics in debugfs

In reply to Venky Shankar
---
 fs/ceph/debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/debugfs.c +1 -1
index 3cf7c9c1085b..acc5cb3ad0ef 100644
@@ -186,7 +186,7 @@ static int metrics_latency_show(struct seq_file *s, void *p)
 		spin_lock(&m->lock);
 		total = m->total;
 		sum = m->latency_sum;
-		avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
+		avg = m->latency_avg;
 		min = m->latency_min;
 		max = m->latency_max;
 		sq = m->latency_sq_sum;
Signature · 1 line
2.27.0
#4 lore raw

Re: [PATCH 3/3] ceph: use tracked average r/w/m latencies to display metrics in debugfs

Quoted 10 lines · Venky Shankar
---
 fs/ceph/debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/debugfs.c +0 -0
index 3cf7c9c1085b..acc5cb3ad0ef 100644

fs/ceph/debugfs.c static int metrics_latency_show(struct seq_file *s, void *p) · line 192

Quoted 8 lines
fs/ceph/debugfs.c +1 -1
@@ -186,7 +186,7 @@ static int metrics_latency_show(struct seq_file *s, void *p)
 		spin_lock(&m->lock);
 		total = m->total;
 		sum = m->latency_sum;
-		avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
+		avg = m->latency_avg;
 		min = m->latency_min;
 		max = m->latency_max;
 		sq = m->latency_sq_sum;

I see this warning with this patch:

fs/ceph/debugfs.c: In function ‘metrics_latency_show’:
fs/ceph/debugfs.c:178:20: warning: variable ‘sum’ set but not used [-Wunused-but-set-variable]
178 | s64 total, sum, avg, min, max, sq;
| ^~~

I think the "sum" var can be eliminated from this function now? I'll go ahead and make that change in there. You don't need resend.

Signature · 1 line
Jeff Layton <[email protected]>
Reviewed-by on the v1 series
#5 lore raw
In reply to Venky Shankar
Quoted 21 lines · Venky Shankar

Right now, cumulative read/write/metadata latencies are tracked and are periodically forwarded to the MDS. These meterics are not particularly useful. A much more useful metric is the average latency and standard deviation (stdev) which is what this series of patches aims to do.

The userspace (libcephfs+tool) changes are here::

           https://github.com/ceph/ceph/pull/41397

Note that the cumulative latencies are still forwarded to the MDS but the tool (cephfs-top) ignores it altogether.

Latency standard deviation is calculated in cephfs-top tool.

Venky Shankar (3):
ceph: track average r/w/m latency
ceph: include average/stdev r/w/m latency in mds metrics
ceph: use tracked average r/w/m latencies to display metrics in
debugfs

Quoted 5 lines
  fs/ceph/debugfs.c |  2 +-
  fs/ceph/metric.c  | 44 +++++++++++++++++++++++----------------
  fs/ceph/metric.h  | 52 +++++++++++++++++++++++++++++++++--------------
  3 files changed, 65 insertions(+), 33 deletions(-)

This series looks good to me.

#6 lore raw
In reply to Venky Shankar
Quoted 21 lines · Venky Shankar

Right now, cumulative read/write/metadata latencies are tracked and are periodically forwarded to the MDS. These meterics are not particularly useful. A much more useful metric is the average latency and standard deviation (stdev) which is what this series of patches aims to do.

The userspace (libcephfs+tool) changes are here::

          https://github.com/ceph/ceph/pull/41397

Note that the cumulative latencies are still forwarded to the MDS but the tool (cephfs-top) ignores it altogether.

Latency standard deviation is calculated in cephfs-top tool.

Venky Shankar (3):
ceph: track average r/w/m latency
ceph: include average/stdev r/w/m latency in mds metrics
ceph: use tracked average r/w/m latencies to display metrics in
debugfs

Quoted 5 lines
 fs/ceph/debugfs.c |  2 +-
 fs/ceph/metric.c  | 44 +++++++++++++++++++++++----------------
 fs/ceph/metric.h  | 52 +++++++++++++++++++++++++++++++++--------------
 3 files changed, 65 insertions(+), 33 deletions(-)

Looks good, Venky. Merged into testing branch. I did make a small change to the last patch to fix a compiler warning. PTAL and make sure you're OK with it.

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
#7 lore raw
Quoted 29 lines · Jeff Layton
Quoted 21 lines · Venky Shankar

Right now, cumulative read/write/metadata latencies are tracked and are periodically forwarded to the MDS. These meterics are not particularly useful. A much more useful metric is the average latency and standard deviation (stdev) which is what this series of patches aims to do.

The userspace (libcephfs+tool) changes are here::

          https://github.com/ceph/ceph/pull/41397

Note that the cumulative latencies are still forwarded to the MDS but the tool (cephfs-top) ignores it altogether.

Latency standard deviation is calculated in cephfs-top tool.

Venky Shankar (3):
ceph: track average r/w/m latency
ceph: include average/stdev r/w/m latency in mds metrics
ceph: use tracked average r/w/m latencies to display metrics in
debugfs

Quoted 5 lines
 fs/ceph/debugfs.c |  2 +-
 fs/ceph/metric.c  | 44 +++++++++++++++++++++++----------------
 fs/ceph/metric.h  | 52 +++++++++++++++++++++++++++++++++--------------
 3 files changed, 65 insertions(+), 33 deletions(-)
Quoted 3 lines

Looks good, Venky. Merged into testing branch. I did make a small change to the last patch to fix a compiler warning. PTAL and make sure you're OK with it.

Looks good. Thanks for the fix.

Quoted 5 lines

Thanks,
--
Jeff Layton <[email protected]>

Signature · 2 lines
Cheers,
Venky