Skip to content

Commit fd5772a

Browse files
authored
chore(tiering): Lots of metrics (#2977)
* chore(tiering): Lots of metrics
1 parent 415839d commit fd5772a

17 files changed

+149
-110
lines changed

src/server/common.cc

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -257,34 +257,22 @@ bool ParseDouble(string_view src, double* value) {
257257

258258
#define ADD(x) (x) += o.x
259259

260-
IoMgrStats& IoMgrStats::operator+=(const IoMgrStats& rhs) {
261-
static_assert(sizeof(IoMgrStats) == 16);
262-
263-
read_total += rhs.read_total;
264-
read_delay_usec += rhs.read_delay_usec;
265-
266-
return *this;
267-
}
268-
269260
TieredStats& TieredStats::operator+=(const TieredStats& o) {
270-
static_assert(sizeof(TieredStats) == 48);
271-
272-
ADD(tiered_writes);
273-
ADD(storage_capacity);
274-
ADD(storage_reserved);
275-
ADD(aborted_write_cnt);
276-
ADD(flush_skip_cnt);
277-
ADD(throttled_write_cnt);
278-
279-
return *this;
280-
}
281-
282-
TieredStatsV2& TieredStatsV2::operator+=(const TieredStatsV2& o) {
283-
static_assert(sizeof(TieredStatsV2) == 24);
261+
static_assert(sizeof(TieredStats) == 80);
284262

285263
ADD(total_stashes);
286264
ADD(total_fetches);
265+
ADD(total_cancels);
266+
287267
ADD(allocated_bytes);
268+
ADD(capacity_bytes);
269+
270+
ADD(pending_read_cnt);
271+
ADD(pending_stash_cnt);
272+
273+
ADD(small_bins_cnt);
274+
ADD(small_bins_entries_cnt);
275+
ADD(small_bins_filling_bytes);
288276

289277
return *this;
290278
}

src/server/common.h

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,22 @@ struct LockTagOptions {
5959
static const LockTagOptions& instance();
6060
};
6161

62-
struct IoMgrStats {
63-
uint64_t read_total = 0;
64-
uint64_t read_delay_usec = 0;
65-
66-
IoMgrStats& operator+=(const IoMgrStats& rhs);
67-
};
68-
6962
struct TieredStats {
70-
uint64_t tiered_writes = 0;
71-
72-
size_t storage_capacity = 0;
73-
74-
// how much was reserved by actively stored items.
75-
size_t storage_reserved = 0;
76-
uint64_t aborted_write_cnt = 0;
77-
uint64_t flush_skip_cnt = 0;
78-
uint64_t throttled_write_cnt = 0;
79-
80-
TieredStats& operator+=(const TieredStats&);
81-
};
82-
83-
struct TieredStatsV2 {
8463
size_t total_stashes = 0;
8564
size_t total_fetches = 0;
65+
size_t total_cancels = 0;
66+
8667
size_t allocated_bytes = 0;
68+
size_t capacity_bytes = 0;
8769

88-
TieredStatsV2& operator+=(const TieredStatsV2&);
70+
size_t pending_read_cnt = 0;
71+
size_t pending_stash_cnt = 0;
72+
73+
size_t small_bins_cnt = 0;
74+
size_t small_bins_entries_cnt = 0;
75+
size_t small_bins_filling_bytes = 0;
76+
77+
TieredStats& operator+=(const TieredStats&);
8978
};
9079

9180
struct SearchStats {

src/server/server_family.cc

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,15 +1144,6 @@ void PrintPrometheusMetrics(const Metrics& m, StringResponse* resp) {
11441144
MetricType::COUNTER, &resp->body());
11451145
AppendMetricWithoutLabels("reply_total", "", m.facade_stats.reply_stats.send_stats.count,
11461146
MetricType::COUNTER, &resp->body());
1147-
1148-
// Tiered metrics.
1149-
if (m.disk_stats.read_total > 0) {
1150-
AppendMetricWithoutLabels("tiered_reads_total", "", m.disk_stats.read_total,
1151-
MetricType::COUNTER, &resp->body());
1152-
AppendMetricWithoutLabels("tiered_reads_latency_seconds", "",
1153-
double(m.disk_stats.read_delay_usec) * 1e-6, MetricType::COUNTER,
1154-
&resp->body());
1155-
}
11561147
}
11571148

11581149
AppendMetricWithoutLabels("script_error_total", "", m.facade_stats.reply_stats.script_error_count,
@@ -1845,7 +1836,7 @@ Metrics ServerFamily::GetMetrics() const {
18451836
result.shard_stats += shard->stats();
18461837

18471838
if (shard->tiered_storage_v2()) {
1848-
result.tiered_stats_v2 += shard->tiered_storage_v2()->GetStats();
1839+
result.tiered_stats += shard->tiered_storage_v2()->GetStats();
18491840
}
18501841

18511842
if (shard->search_indices()) {
@@ -2057,23 +2048,19 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
20572048
}
20582049

20592050
if (should_enter("TIERED", true)) {
2060-
append("tiered_entries", total.tiered_entries);
2061-
append("tiered_bytes", total.tiered_size);
2062-
append("tiered_bytes_human", HumanReadableNumBytes(total.tiered_size));
2063-
append("tiered_reads", m.disk_stats.read_total);
2064-
append("tiered_read_latency_usec", m.disk_stats.read_delay_usec);
2065-
append("tiered_writes", m.tiered_stats.tiered_writes);
2066-
append("tiered_reserved", m.tiered_stats.storage_reserved);
2067-
append("tiered_capacity", m.tiered_stats.storage_capacity);
2068-
append("tiered_aborted_writes", m.tiered_stats.aborted_write_cnt);
2069-
append("tiered_flush_skipped", m.tiered_stats.flush_skip_cnt);
2070-
append("tiered_throttled_writes", m.tiered_stats.throttled_write_cnt);
2071-
}
2072-
2073-
if (should_enter("TIERED_V2", true)) {
2074-
append("tiered_v2_total_stashes", m.tiered_stats_v2.total_stashes);
2075-
append("tiered_v2_total_fetches", m.tiered_stats_v2.total_fetches);
2076-
append("tiered_v2_allocated_bytes", m.tiered_stats_v2.allocated_bytes);
2051+
append("tiered_total_stashes", m.tiered_stats.total_stashes);
2052+
append("tiered_total_fetches", m.tiered_stats.total_fetches);
2053+
append("tiered_total_cancels", m.tiered_stats.total_cancels);
2054+
2055+
append("tiered_allocated_bytes", m.tiered_stats.allocated_bytes);
2056+
append("tiered_capacity_bytes", m.tiered_stats.capacity_bytes);
2057+
2058+
append("tiered_pending_read_cnt", m.tiered_stats.pending_read_cnt);
2059+
append("tiered_pending_stash_cnt", m.tiered_stats.pending_stash_cnt);
2060+
2061+
append("tiered_small_bins_cnt", m.tiered_stats.small_bins_cnt);
2062+
append("tiered_small_bins_entries_cnt", m.tiered_stats.small_bins_entries_cnt);
2063+
append("tiered_small_bins_filling_bytes", m.tiered_stats.small_bins_filling_bytes);
20772064
}
20782065

20792066
if (should_enter("PERSISTENCE", true)) {

src/server/server_family.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ struct Metrics {
8080
EngineShard::Stats shard_stats; // per-shard stats
8181

8282
facade::FacadeStats facade_stats; // client stats and buffer sizes
83-
TieredStats tiered_stats; // stats for tiered storage
84-
TieredStatsV2 tiered_stats_v2;
83+
TieredStats tiered_stats;
8584

86-
IoMgrStats disk_stats; // disk stats for io_mgr
8785
SearchStats search_stats;
8886
ServerState::Stats coordinator_stats; // stats on transaction running
8987
PeakStats peak_stats;

src/server/tiered_storage.cc

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ class TieredStorageV2::ShardOpManager : public tiering::OpManager {
5858

5959
// Clear IO pending flag for entry
6060
void ClearIoPending(string_view key) {
61-
if (auto pv = Find(key); pv)
61+
if (auto pv = Find(key); pv) {
6262
pv->SetIoPending(false);
63+
stats_.total_cancels++;
64+
}
6365
}
6466

6567
// Clear IO pending flag for all contained entries of bin
@@ -109,13 +111,9 @@ class TieredStorageV2::ShardOpManager : public tiering::OpManager {
109111
}
110112
}
111113

112-
TieredStatsV2 GetStats() const {
113-
auto stats = stats_;
114-
stats.allocated_bytes = OpManager::storage_.GetStats().allocated_bytes;
115-
return stats;
116-
}
117-
118114
private:
115+
friend class TieredStorageV2;
116+
119117
PrimeValue* Find(string_view key) {
120118
// TODO: Get DbContext for transaction for correct dbid and time
121119
auto it = db_slice_->FindMutable(DbContext{}, key);
@@ -124,7 +122,9 @@ class TieredStorageV2::ShardOpManager : public tiering::OpManager {
124122

125123
bool cache_fetched_ = false;
126124

127-
TieredStatsV2 stats_;
125+
struct {
126+
size_t total_stashes = 0, total_fetches = 0, total_cancels = 0;
127+
} stats_;
128128

129129
TieredStorageV2* ts_;
130130
DbSlice* db_slice_;
@@ -218,8 +218,32 @@ bool TieredStorageV2::ShouldStash(const PrimeValue& pv) {
218218
return !pv.IsExternal() && pv.ObjType() == OBJ_STRING && pv.Size() >= kMinValueSize;
219219
}
220220

221-
TieredStatsV2 TieredStorageV2::GetStats() const {
222-
return op_manager_->GetStats();
221+
TieredStats TieredStorageV2::GetStats() const {
222+
TieredStats stats{};
223+
224+
{ // ShardOpManager stats
225+
auto shard_stats = op_manager_->stats_;
226+
stats.total_fetches = shard_stats.total_fetches;
227+
stats.total_stashes = shard_stats.total_stashes;
228+
stats.total_cancels = shard_stats.total_cancels;
229+
}
230+
231+
{ // OpManager stats
232+
tiering::OpManager::Stats op_stats = op_manager_->GetStats();
233+
stats.pending_read_cnt = op_stats.pending_read_cnt;
234+
stats.pending_stash_cnt = op_stats.pending_stash_cnt;
235+
stats.allocated_bytes = op_stats.disk_stats.allocated_bytes;
236+
stats.capacity_bytes = op_stats.disk_stats.capacity_bytes;
237+
}
238+
239+
{ // SmallBins stats
240+
tiering::SmallBins::Stats bins_stats = bins_->GetStats();
241+
stats.small_bins_cnt = bins_stats.stashed_bins_cnt;
242+
stats.small_bins_entries_cnt = bins_stats.stashed_entries_cnt;
243+
stats.small_bins_filling_bytes = bins_stats.current_bin_bytes;
244+
}
245+
246+
return stats;
223247
}
224248

225249
} // namespace dfly

src/server/tiered_storage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TieredStorageV2 {
5858
// Returns if a value should be stashed
5959
bool ShouldStash(const PrimeValue& pv);
6060

61-
TieredStatsV2 GetStats() const;
61+
TieredStats GetStats() const;
6262

6363
private:
6464
std::unique_ptr<ShardOpManager> op_manager_;
@@ -108,8 +108,8 @@ class TieredStorageV2 {
108108
void Delete(std::string_view key, PrimeValue* value) {
109109
}
110110

111-
TieredStatsV2 GetStats() {
112-
return TieredStatsV2{};
111+
TieredStats GetStats() {
112+
return TieredStats{};
113113
}
114114
};
115115

src/server/tiered_storage_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ TEST_F(TieredStorageV2Test, SimpleGetSet) {
6363
// Make sure all entries were stashed, except the one few not filling a small page
6464
size_t stashes = 0;
6565
ExpectConditionWithinTimeout([this, &stashes] {
66-
stashes = GetMetrics().tiered_stats_v2.total_stashes;
66+
stashes = GetMetrics().tiered_stats.total_stashes;
6767
return stashes >= kMax - 64 - 1;
6868
});
6969

src/server/tiering/disk_storage.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ std::error_code DiskStorage::Stash(io::Bytes bytes, StashCb cb) {
119119
memcpy(buf.bytes.data(), bytes.data(), bytes.length());
120120

121121
auto io_cb = [this, cb, offset, buf, len = bytes.size()](int io_res) {
122-
VLOG(0) << "IoRes " << io_res << " " << len;
123122
if (io_res < 0) {
124123
MarkAsFree({size_t(offset), len});
125124
cb({}, std::error_code{-io_res, std::system_category()});
@@ -134,7 +133,7 @@ std::error_code DiskStorage::Stash(io::Bytes bytes, StashCb cb) {
134133
}
135134

136135
DiskStorage::Stats DiskStorage::GetStats() const {
137-
return {alloc_.allocated_bytes()};
136+
return {alloc_.allocated_bytes(), alloc_.capacity()};
138137
}
139138

140139
} // namespace dfly::tiering

src/server/tiering/disk_storage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class DiskStorage {
1919
public:
2020
struct Stats {
2121
size_t allocated_bytes = 0;
22+
size_t capacity_bytes = 0;
2223
};
2324

2425
using ReadCb = std::function<void(std::string_view, std::error_code)>;

src/server/tiering/disk_storage_test.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "base/gtest.h"
1010
#include "base/logging.h"
11+
#include "server/tiering/common.h"
1112
#include "server/tiering/test_common.h"
1213
#include "util/fibers/fibers.h"
1314
#include "util/fibers/pool.h"
@@ -59,12 +60,16 @@ struct DiskStorageTest : public PoolTestBase {
5960
last_reads_.erase(index);
6061
}
6162

62-
void Wait() {
63+
void Wait() const {
6364
while (pending_ops_ > 0) {
6465
::util::ThisFiber::SleepFor(1ms);
6566
}
6667
}
6768

69+
DiskStorage::Stats GetStats() const {
70+
return storage_->GetStats();
71+
}
72+
6873
protected:
6974
int pending_ops_ = 0;
7075

@@ -82,6 +87,8 @@ TEST_F(DiskStorageTest, Basic) {
8287
Wait();
8388
EXPECT_EQ(segments_.size(), 100);
8489

90+
EXPECT_EQ(GetStats().allocated_bytes, 100 * kPageSize);
91+
8592
// Read all 100 values
8693
for (size_t i = 0; i < 100; i++)
8794
Read(i);
@@ -91,6 +98,11 @@ TEST_F(DiskStorageTest, Basic) {
9198
for (size_t i = 0; i < 100; i++)
9299
EXPECT_EQ(last_reads_[i], absl::StrCat("value", i));
93100

101+
// Delete all values
102+
for (size_t i = 0; i < 100; i++)
103+
Delete(i);
104+
EXPECT_EQ(GetStats().allocated_bytes, 0);
105+
94106
Close();
95107
});
96108
}

0 commit comments

Comments
 (0)