Skip to content

Commit 4163383

Browse files
kostasrimromange
authored andcommitted
chore: add metrics for heartbeat evictions (#4952)
* evict in heartbeat if expire table is not empty * add metrics around heartbeat evictions (total evictions and total evicted bytes) Signed-off-by: kostas <kostas@dragonflydb.io>
1 parent 4b0676c commit 4163383

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/server/engine_shard.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ string EngineShard::TxQueueInfo::Format() const {
297297
}
298298

299299
EngineShard::Stats& EngineShard::Stats::operator+=(const EngineShard::Stats& o) {
300-
static_assert(sizeof(Stats) == 64);
300+
static_assert(sizeof(Stats) == 88);
301301

302302
#define ADD(x) x += o.x
303303

@@ -309,6 +309,9 @@ EngineShard::Stats& EngineShard::Stats::operator+=(const EngineShard::Stats& o)
309309
ADD(tx_optimistic_total);
310310
ADD(tx_batch_schedule_calls_total);
311311
ADD(tx_batch_scheduled_items_total);
312+
ADD(total_heartbeat_expired_keys);
313+
ADD(total_heartbeat_expired_bytes);
314+
ADD(total_heartbeat_expired_calls);
312315

313316
#undef ADD
314317
return *this;
@@ -802,12 +805,18 @@ void EngineShard::RetireExpiredAndEvict() {
802805

803806
db_cntx.db_index = i;
804807
auto [pt, expt] = db_slice.GetTables(i);
805-
if (expt->size() > pt->size() / 4) {
808+
if (expt->size() > 0) {
806809
DbSlice::DeleteExpiredStats stats = db_slice.DeleteExpiredStep(db_cntx, ttl_delete_target);
807810

808811
eviction_goal -= std::min(eviction_goal, size_t(stats.deleted_bytes));
809812
counter_[TTL_TRAVERSE].IncBy(stats.traversed);
810813
counter_[TTL_DELETE].IncBy(stats.deleted);
814+
stats_.total_heartbeat_expired_keys += stats.deleted;
815+
stats_.total_heartbeat_expired_bytes += stats.deleted_bytes;
816+
++stats_.total_heartbeat_expired_calls;
817+
VLOG(1) << "Heartbeat expired " << stats.deleted << " keys with total bytes "
818+
<< stats.deleted_bytes << " with total expire flow calls "
819+
<< stats_.total_heartbeat_expired_calls;
811820
}
812821

813822
if (eviction_goal) {

src/server/engine_shard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class EngineShard {
4444
// Number of transactions scheduled via ScheduleBatchInShard.
4545
uint64_t tx_batch_scheduled_items_total = 0;
4646

47+
uint64_t total_heartbeat_expired_keys = 0;
48+
uint64_t total_heartbeat_expired_bytes = 0;
49+
uint64_t total_heartbeat_expired_calls = 0;
50+
4751
Stats& operator+=(const Stats&);
4852
};
4953

src/server/server_family.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,9 @@ string ServerFamily::FormatInfoMetrics(const Metrics& m, std::string_view sectio
24842484
append("rejected_connections", -1);
24852485
append("expired_keys", m.events.expired_keys);
24862486
append("evicted_keys", m.events.evicted_keys);
2487+
append("total_heartbeat_expired_keys", m.shard_stats.total_heartbeat_expired_keys);
2488+
append("total_heartbeat_expired_bytes", m.shard_stats.total_heartbeat_expired_bytes);
2489+
append("total_heartbeat_expired_calls", m.shard_stats.total_heartbeat_expired_calls);
24872490
append("hard_evictions", m.events.hard_evictions);
24882491
append("garbage_checked", m.events.garbage_checked);
24892492
append("garbage_collected", m.events.garbage_collected);

0 commit comments

Comments
 (0)