Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions TreeDB/caching/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ const (
postFlushAppendOnlyMemLeaseKeep = 24
postCheckpointAppendOnlyMemLeaseKeep = 8
appendOnlyEntryPoolHighPressureDropBytes = uint64(32 << 20)
appendOnlyKeyArenaPoolHighPressureDropBytes = uint64(32 << 20)
appendOnlyValueArenaPoolHighPressureDropBytes = uint64(32 << 20)
)

Expand Down Expand Up @@ -760,6 +761,7 @@ func maybeTrimEntrySliceLeasesUnderPressure(level poolPressureLevel, sampledAt t
entrySlicePoolTrimDropBytesTotal.Add(uint64(droppedBytes))
}
maybeDropAppendOnlyEntryPoolsUnderPressure(level)
maybeDropAppendOnlyKeyArenaPoolsUnderPressure(level)
maybeDropAppendOnlyValueArenaPoolsUnderPressure(level)
}

Expand All @@ -778,6 +780,21 @@ func maybeDropAppendOnlyEntryPoolsUnderPressure(level poolPressureLevel) {
memtable.DropAppendOnlyEntryPools()
}

func maybeDropAppendOnlyKeyArenaPoolsUnderPressure(level poolPressureLevel) {
if level == poolPressureNormal {
return
}
stats := memtable.AppendOnlyKeyArenaPoolStatsSnapshot()
retainedBytes := stats.RetainedBytesEstimate
if retainedBytes == 0 {
return
}
if level != poolPressureCritical && retainedBytes < appendOnlyKeyArenaPoolHighPressureDropBytes {
return
}
memtable.DropAppendOnlyKeyArenaPools()
}

func maybeDropAppendOnlyValueArenaPoolsUnderPressure(level poolPressureLevel) {
if level == poolPressureNormal {
return
Expand Down Expand Up @@ -10719,6 +10736,7 @@ func (db *DB) dropColdAppendOnlyPools() {
db.appendOnlyMemPool.Store(&sync.Pool{})
db.appendOnlyMemPoolDropTotal.Add(1)
memtable.DropAppendOnlyEntryPools()
memtable.DropAppendOnlyKeyArenaPools()
memtable.DropAppendOnlyValueArenaPools()
}

Expand Down Expand Up @@ -30089,6 +30107,7 @@ func (db *DB) Stats() map[string]string {
appendOnlyMemNewAllocQueueBytes := db.appendOnlyMemNewAllocQueueBytes.Load()
appendOnlyMemPoolDropTotal := db.appendOnlyMemPoolDropTotal.Load()
appendOnlyEntryPoolStats := memtable.AppendOnlyEntryPoolStatsSnapshot()
appendOnlyKeyArenaPoolStats := memtable.AppendOnlyKeyArenaPoolStatsSnapshot()
appendOnlyValueArenaPoolStats := memtable.AppendOnlyValueArenaPoolStatsSnapshot()
appendOnlyEntryReserveStats := memtable.AppendOnlyEntryReserveStatsSnapshot()
appendOnlyMemLeaseCount, appendOnlyMemLeaseEntryCapacity, appendOnlyMemLeaseEntryBackingBytes, appendOnlyMemLeaseValueArena := db.appendOnlyMemLeaseStats()
Expand All @@ -30108,6 +30127,14 @@ func (db *DB) Stats() map[string]string {
stats["treedb.cache.append_only.entry_pool_drop_bytes_total"] = fmt.Sprintf("%d", appendOnlyEntryPoolStats.DropBytesTotal)
stats["treedb.cache.append_only.entry_pool_admission_drops_total"] = fmt.Sprintf("%d", appendOnlyEntryPoolStats.AdmissionDropsTotal)
stats["treedb.cache.append_only.entry_pool_admission_drop_bytes_total"] = fmt.Sprintf("%d", appendOnlyEntryPoolStats.AdmissionDropBytesTotal)
stats["treedb.cache.append_only.key_arena_pool_retained_bytes_estimate"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.RetainedBytesEstimate)
stats["treedb.cache.append_only.key_arena_pool_retained_bytes_max_estimate"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.RetainedBytesMaxEstimate)
stats["treedb.cache.append_only.key_arena_pool_gets_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.GetsTotal)
stats["treedb.cache.append_only.key_arena_pool_puts_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.PutsTotal)
stats["treedb.cache.append_only.key_arena_pool_drops_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.DropsTotal)
stats["treedb.cache.append_only.key_arena_pool_drop_bytes_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.DropBytesTotal)
stats["treedb.cache.append_only.key_arena_pool_admission_drops_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.AdmissionDropsTotal)
stats["treedb.cache.append_only.key_arena_pool_admission_drop_bytes_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.AdmissionDropBytesTotal)
stats["treedb.cache.append_only.value_arena_pool_retained_bytes_estimate"] = fmt.Sprintf("%d", appendOnlyValueArenaPoolStats.RetainedBytesEstimate)
stats["treedb.cache.append_only.value_arena_pool_retained_bytes_max_estimate"] = fmt.Sprintf("%d", appendOnlyValueArenaPoolStats.RetainedBytesMaxEstimate)
stats["treedb.cache.append_only.value_arena_pool_gets_total"] = fmt.Sprintf("%d", appendOnlyValueArenaPoolStats.GetsTotal)
Expand Down Expand Up @@ -30158,6 +30185,14 @@ func (db *DB) Stats() map[string]string {
stats["treedb.process.append_only.entry_pool_drop_bytes_total"] = fmt.Sprintf("%d", appendOnlyEntryPoolStats.DropBytesTotal)
stats["treedb.process.append_only.entry_pool_admission_drops_total"] = fmt.Sprintf("%d", appendOnlyEntryPoolStats.AdmissionDropsTotal)
stats["treedb.process.append_only.entry_pool_admission_drop_bytes_total"] = fmt.Sprintf("%d", appendOnlyEntryPoolStats.AdmissionDropBytesTotal)
stats["treedb.process.append_only.key_arena_pool_retained_bytes_estimate"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.RetainedBytesEstimate)
stats["treedb.process.append_only.key_arena_pool_retained_bytes_max_estimate"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.RetainedBytesMaxEstimate)
stats["treedb.process.append_only.key_arena_pool_gets_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.GetsTotal)
stats["treedb.process.append_only.key_arena_pool_puts_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.PutsTotal)
stats["treedb.process.append_only.key_arena_pool_drops_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.DropsTotal)
stats["treedb.process.append_only.key_arena_pool_drop_bytes_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.DropBytesTotal)
stats["treedb.process.append_only.key_arena_pool_admission_drops_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.AdmissionDropsTotal)
stats["treedb.process.append_only.key_arena_pool_admission_drop_bytes_total"] = fmt.Sprintf("%d", appendOnlyKeyArenaPoolStats.AdmissionDropBytesTotal)
stats["treedb.process.append_only.value_arena_pool_retained_bytes_estimate"] = fmt.Sprintf("%d", appendOnlyValueArenaPoolStats.RetainedBytesEstimate)
stats["treedb.process.append_only.value_arena_pool_retained_bytes_max_estimate"] = fmt.Sprintf("%d", appendOnlyValueArenaPoolStats.RetainedBytesMaxEstimate)
stats["treedb.process.append_only.value_arena_pool_gets_total"] = fmt.Sprintf("%d", appendOnlyValueArenaPoolStats.GetsTotal)
Expand Down
28 changes: 28 additions & 0 deletions TreeDB/caching/memory_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ func TestProcessMemoryStatsIncludeRuntimeBreakdown(t *testing.T) {
"treedb.cache.append_only.entry_pool_drop_bytes_total",
"treedb.cache.append_only.entry_pool_admission_drops_total",
"treedb.cache.append_only.entry_pool_admission_drop_bytes_total",
"treedb.cache.append_only.key_arena_pool_retained_bytes_estimate",
"treedb.cache.append_only.key_arena_pool_retained_bytes_max_estimate",
"treedb.cache.append_only.key_arena_pool_gets_total",
"treedb.cache.append_only.key_arena_pool_puts_total",
"treedb.cache.append_only.key_arena_pool_drops_total",
"treedb.cache.append_only.key_arena_pool_drop_bytes_total",
"treedb.cache.append_only.key_arena_pool_admission_drops_total",
"treedb.cache.append_only.key_arena_pool_admission_drop_bytes_total",
"treedb.cache.append_only.value_arena_pool_retained_bytes_estimate",
"treedb.cache.append_only.value_arena_pool_retained_bytes_max_estimate",
"treedb.cache.append_only.value_arena_pool_gets_total",
Expand Down Expand Up @@ -195,6 +203,14 @@ func TestProcessMemoryStatsIncludeRuntimeBreakdown(t *testing.T) {
"treedb.process.append_only.entry_pool_drop_bytes_total",
"treedb.process.append_only.entry_pool_admission_drops_total",
"treedb.process.append_only.entry_pool_admission_drop_bytes_total",
"treedb.process.append_only.key_arena_pool_retained_bytes_estimate",
"treedb.process.append_only.key_arena_pool_retained_bytes_max_estimate",
"treedb.process.append_only.key_arena_pool_gets_total",
"treedb.process.append_only.key_arena_pool_puts_total",
"treedb.process.append_only.key_arena_pool_drops_total",
"treedb.process.append_only.key_arena_pool_drop_bytes_total",
"treedb.process.append_only.key_arena_pool_admission_drops_total",
"treedb.process.append_only.key_arena_pool_admission_drop_bytes_total",
"treedb.process.append_only.value_arena_pool_retained_bytes_estimate",
"treedb.process.append_only.value_arena_pool_retained_bytes_max_estimate",
"treedb.process.append_only.value_arena_pool_gets_total",
Expand Down Expand Up @@ -275,6 +291,18 @@ func TestProcessMemoryStatsIncludeRuntimeBreakdown(t *testing.T) {
if got := mustStatInt64(t, stats, "treedb.process.append_only.entry_pool_admission_drop_bytes_total"); got != mustStatInt64(t, stats, "treedb.cache.append_only.entry_pool_admission_drop_bytes_total") {
t.Fatalf("append_only entry pool admission drop bytes mismatch process=%d cache=%d", got, mustStatInt64(t, stats, "treedb.cache.append_only.entry_pool_admission_drop_bytes_total"))
}
if got := mustStatInt64(t, stats, "treedb.process.append_only.key_arena_pool_retained_bytes_estimate"); got != mustStatInt64(t, stats, "treedb.cache.append_only.key_arena_pool_retained_bytes_estimate") {
t.Fatalf("append_only key arena pool retained mismatch process=%d cache=%d", got, mustStatInt64(t, stats, "treedb.cache.append_only.key_arena_pool_retained_bytes_estimate"))
}
if got := mustStatInt64(t, stats, "treedb.process.append_only.key_arena_pool_drop_bytes_total"); got != mustStatInt64(t, stats, "treedb.cache.append_only.key_arena_pool_drop_bytes_total") {
t.Fatalf("append_only key arena pool drop bytes mismatch process=%d cache=%d", got, mustStatInt64(t, stats, "treedb.cache.append_only.key_arena_pool_drop_bytes_total"))
}
if got := mustStatInt64(t, stats, "treedb.process.append_only.key_arena_pool_admission_drops_total"); got != mustStatInt64(t, stats, "treedb.cache.append_only.key_arena_pool_admission_drops_total") {
t.Fatalf("append_only key arena pool admission drops mismatch process=%d cache=%d", got, mustStatInt64(t, stats, "treedb.cache.append_only.key_arena_pool_admission_drops_total"))
}
if got := mustStatInt64(t, stats, "treedb.process.append_only.key_arena_pool_admission_drop_bytes_total"); got != mustStatInt64(t, stats, "treedb.cache.append_only.key_arena_pool_admission_drop_bytes_total") {
t.Fatalf("append_only key arena pool admission drop bytes mismatch process=%d cache=%d", got, mustStatInt64(t, stats, "treedb.cache.append_only.key_arena_pool_admission_drop_bytes_total"))
}
if got := mustStatInt64(t, stats, "treedb.process.append_only.value_arena_pool_retained_bytes_estimate"); got != mustStatInt64(t, stats, "treedb.cache.append_only.value_arena_pool_retained_bytes_estimate") {
t.Fatalf("append_only value arena pool retained mismatch process=%d cache=%d", got, mustStatInt64(t, stats, "treedb.cache.append_only.value_arena_pool_retained_bytes_estimate"))
}
Expand Down
21 changes: 20 additions & 1 deletion TreeDB/caching/pool_pressure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ func TestPoolPressureDropsAppendOnlyEntryPools(t *testing.T) {

resetPoolPressureStateForTest()
memtable.DropAppendOnlyEntryPools()
memtable.DropAppendOnlyKeyArenaPools()
memtable.DropAppendOnlyValueArenaPools()
t.Cleanup(func() {
memtable.DropAppendOnlyEntryPools()
memtable.DropAppendOnlyKeyArenaPools()
memtable.DropAppendOnlyValueArenaPools()
resetPoolPressureStateForTest()
})
Expand All @@ -175,8 +177,15 @@ func TestPoolPressureDropsAppendOnlyEntryPools(t *testing.T) {
if before.RetainedBytesEstimate == 0 {
t.Fatal("test setup did not retain append-only entry pool bytes")
}
keyArena := memtable.NewAppendOnlyWithCapacity(0)
keyArena.Set([]byte("key-arena-retained-chunk"), nil)
keyArena.Reset()
beforeKeyArena := memtable.AppendOnlyKeyArenaPoolStatsSnapshot()
if beforeKeyArena.RetainedBytesEstimate == 0 {
t.Fatal("test setup did not retain append-only key arena pool bytes")
}
valueArena := memtable.NewAppendOnlyWithCapacity(0)
valueArena.Set([]byte("value-arena-key"), make([]byte, 4096))
valueArena.Set([]byte("valuekey"), make([]byte, 4096))
valueArena.ResetDropEntries()
beforeValueArena := memtable.AppendOnlyValueArenaPoolStatsSnapshot()
if beforeValueArena.RetainedBytesEstimate == 0 {
Expand All @@ -195,6 +204,16 @@ func TestPoolPressureDropsAppendOnlyEntryPools(t *testing.T) {
if got := after.DropBytesTotal; got < before.DropBytesTotal+before.RetainedBytesEstimate {
t.Fatalf("append-only entry pool drop bytes=%d want at least %d", got, before.DropBytesTotal+before.RetainedBytesEstimate)
}
afterKeyArena := memtable.AppendOnlyKeyArenaPoolStatsSnapshot()
if got := afterKeyArena.RetainedBytesEstimate; got != 0 {
t.Fatalf("append-only key arena pool retained bytes=%d want 0", got)
}
if got := afterKeyArena.DropsTotal; got != beforeKeyArena.DropsTotal+1 {
t.Fatalf("append-only key arena pool drops=%d want %d", got, beforeKeyArena.DropsTotal+1)
}
if got := afterKeyArena.DropBytesTotal; got < beforeKeyArena.DropBytesTotal+beforeKeyArena.RetainedBytesEstimate {
t.Fatalf("append-only key arena pool drop bytes=%d want at least %d", got, beforeKeyArena.DropBytesTotal+beforeKeyArena.RetainedBytesEstimate)
}
afterValueArena := memtable.AppendOnlyValueArenaPoolStatsSnapshot()
if got := afterValueArena.RetainedBytesEstimate; got != 0 {
t.Fatalf("append-only value arena pool retained bytes=%d want 0", got)
Expand Down
4 changes: 4 additions & 0 deletions TreeDB/caching/retained_arena_trim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func TestStoreMemtableMode_DropsAppendOnlyPoolsOnColdTransition(t *testing.T) {
t.Fatal("expected append-only memtable pool")
}
beforeEntryPoolDrops := memtable.AppendOnlyEntryPoolDropTotal()
beforeKeyArenaPoolDrops := memtable.AppendOnlyKeyArenaPoolDropTotal()
beforeValueArenaPoolDrops := memtable.AppendOnlyValueArenaPoolDropTotal()

db.storeMemtableMode(memtable.ModeBTree)
Expand All @@ -179,6 +180,9 @@ func TestStoreMemtableMode_DropsAppendOnlyPoolsOnColdTransition(t *testing.T) {
if got := memtable.AppendOnlyEntryPoolDropTotal(); got != beforeEntryPoolDrops+1 {
t.Fatalf("append-only entry pool drops=%d want %d", got, beforeEntryPoolDrops+1)
}
if got := memtable.AppendOnlyKeyArenaPoolDropTotal(); got != beforeKeyArenaPoolDrops+1 {
t.Fatalf("append-only key arena pool drops=%d want %d", got, beforeKeyArenaPoolDrops+1)
}
if got := memtable.AppendOnlyValueArenaPoolDropTotal(); got != beforeValueArenaPoolDrops+1 {
t.Fatalf("append-only value arena pool drops=%d want %d", got, beforeValueArenaPoolDrops+1)
}
Expand Down
Loading
Loading