From 71f2a8edcfa6e02b6c8a40e0deb71145234d9932 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Thu, 3 Dec 2026 10:02:39 +0300 Subject: [PATCH] mon: Do not truncate per-OSD iops before summing them derive_osd_stats() divided every OSD's op count by its report interval in integer arithmetic, and sum_op_stats() and sum_inode_stats() added up the truncated rates. An OSD reports every etcd_stats_interval (30 s by default), so an OSD serving less than 1 op/s of an image added nothing: an image spread over many OSDs lost up to 1 op/s per OSD and showed 0 iops and 0 latency under light load. Total client iops lost the same. Keep per-OSD iops in 1/1000 op/s and round each sum up once, so that any I/O shows as at least 1 op/s. The format of /stats and /inode/stats does not change. --- mon/stats.js | 14 ++++++++++---- mon/test-stats-iops.js | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 mon/test-stats-iops.js diff --git a/mon/stats.js b/mon/stats.js index 9d516bd7..48761760 100644 --- a/mon/stats.js +++ b/mon/stats.js @@ -9,6 +9,7 @@ function derive_osd_stats(st, prev, prev_diff) return diff; } const timediff = BigInt(st.time*1000 - prev.time*1000); + // iops are in 1/1000 op/s until sum_op_stats() and sum_inode_stats() add them up for (const op in st.op_stats||{}) { const pr = prev && prev.op_stats && prev.op_stats[op]; @@ -17,7 +18,7 @@ function derive_osd_stats(st, prev, prev_diff) const b = c.bytes - BigInt(pr && pr.bytes||0); const us = c.usec - BigInt(pr && pr.usec||0); const n = c.count - BigInt(pr && pr.count||0); - diff.op_stats[op] = { ...c, bps: n > 0 ? b*1000n/timediff : 0n, iops: n > 0 ? n*1000n/timediff : 0n, lat: n > 0 ? us/n : 0n }; + diff.op_stats[op] = { ...c, bps: n > 0 ? b*1000n/timediff : 0n, iops: n > 0 ? n*1000000n/timediff : 0n, lat: n > 0 ? us/n : 0n }; } for (const op in st.subop_stats||{}) { @@ -26,7 +27,7 @@ function derive_osd_stats(st, prev, prev_diff) c = { usec: BigInt(c.usec||0), count: BigInt(c.count||0) }; const us = c.usec - BigInt(pr && pr.usec||0); const n = c.count - BigInt(pr && pr.count||0); - diff.subop_stats[op] = { ...c, iops: n > 0 ? n*1000n/timediff : 0n, lat: n > 0 ? us/n : 0n }; + diff.subop_stats[op] = { ...c, iops: n > 0 ? n*1000000n/timediff : 0n, lat: n > 0 ? us/n : 0n }; } for (const op in st.recovery_stats||{}) { @@ -35,7 +36,7 @@ function derive_osd_stats(st, prev, prev_diff) c = { bytes: BigInt(c.bytes||0), count: BigInt(c.count||0) }; const b = c.bytes - BigInt(pr && pr.bytes||0); const n = c.count - BigInt(pr && pr.count||0); - diff.recovery_stats[op] = { ...c, bps: n > 0 ? b*1000n/timediff : 0n, iops: n > 0 ? n*1000n/timediff : 0n }; + diff.recovery_stats[op] = { ...c, bps: n > 0 ? b*1000n/timediff : 0n, iops: n > 0 ? n*1000000n/timediff : 0n }; } diff.inode_stats = {}; for (const pool_id in st.inode_stats||{}) @@ -52,7 +53,7 @@ function derive_osd_stats(st, prev, prev_diff) const n = BigInt(c.count||0) - BigInt(pr && pr.count||0); inode_diff[op] = { bps: n > 0 ? (BigInt(c.bytes||0) - BigInt(pr && pr.bytes||0))*1000n/timediff : 0n, - iops: n > 0 ? n*1000n/timediff : 0n, + iops: n > 0 ? n*1000000n/timediff : 0n, lat: n > 0 ? (BigInt(c.usec||0) - BigInt(pr && pr.usec||0))/n : 0n, }; } @@ -105,6 +106,10 @@ function sum_op_stats(all_osd, prev_stats) { sum_diff[type][op].lat /= sum_diff[type][op].iops; } + if (sum_diff[type][op].iops) + { + sum_diff[type][op].iops = (sum_diff[type][op].iops + 999n) / 1000n; + } } } return sum_diff; @@ -305,6 +310,7 @@ function sum_inode_stats(state, prev_stats) const op_st = inode_stats[pool_id][inode_num][op]; if (op_st.lat) op_st.lat /= op_st.iops; + op_st.iops = (op_st.iops + 999n) / 1000n; if (op_st.bps > 0 || op_st.iops > 0) nonzero = true; } diff --git a/mon/test-stats-iops.js b/mon/test-stats-iops.js new file mode 100644 index 00000000..cde708c8 --- /dev/null +++ b/mon/test-stats-iops.js @@ -0,0 +1,43 @@ +// Copyright (c) Vitaliy Filippov, 2019+ +// License: VNPL-1.1 (see README.md for details) + +// Rates summed over OSDs that each serve less than 1 op/s. Run: node mon/test-stats-iops.js + +const assert = require('assert'); +const { sum_op_stats, sum_inode_stats } = require('./stats.js'); + +// One image read at 0.8 op/s on each of OSDs, 200 us per op, OSD stats reported every 5 s +function run(osds) +{ + const prev_stats = { osd_stats: {}, osd_diff: {} }; + let res; + for (let round = 1; round <= 2; round++) + { + const st = { count: 4*round, usec: 800*round, bytes: 16384*round }; + const state = { + config: { pools: { 1: {} }, inode: { 1: { 1: {} } } }, + pool: { stats: {} }, + osd: { state: {}, stats: {}, inodestats: {}, space: {} }, + }; + for (let osd = 1; osd <= osds; osd++) + { + state.osd.state[osd] = { state: 'up' }; + state.osd.stats[osd] = { time: 5*round, op_stats: { primary_read: st } }; + state.osd.inodestats[osd] = { 1: { 1: { read: st, write: {}, delete: {} } } }; + } + res = { stats: sum_op_stats(state.osd, prev_stats), inode: sum_inode_stats(state, prev_stats).inode_stats[1][1] }; + } + return res; +} + +let { stats, inode } = run(48); +// 48 * 0.8 = 38.4 op/s, rounded up +assert.equal(stats.op_stats.primary_read.iops, 39n); +assert.equal(stats.op_stats.primary_read.lat, 200n); +assert.equal(inode.read.iops, 39n); +assert.equal(inode.read.lat, 200n); +({ stats, inode } = run(1)); +// Any I/O shows as at least 1 op/s +assert.equal(inode.read.iops, 1n); +assert.equal(inode.read.lat, 200n); +console.log('OK'); -- 2.47.3