Skip to content

Commit 02b796b

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
32 shards
1 parent 3f444db commit 02b796b

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

cache_persist_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,15 @@ func TestCache_GhostQueue(t *testing.T) {
593593
func TestCache_MainQueueEviction(t *testing.T) {
594594
ctx := context.Background()
595595

596-
// Create cache with capacity divisible by 16 shards (48 = 3 per shard)
597-
cache, err := New[string, int](ctx, WithMemorySize(48))
596+
// Create cache with capacity divisible by 32 shards (64 = 2 per shard)
597+
cache, err := New[string, int](ctx, WithMemorySize(64))
598598
if err != nil {
599599
t.Fatalf("New: %v", err)
600600
}
601601
defer func() { _ = cache.Close() }() //nolint:errcheck // Test cleanup
602602

603603
// Insert and access items to get them into Main queue
604-
for i := range 72 {
604+
for i := range 96 {
605605
key := fmt.Sprintf("key%d", i)
606606
if err := cache.Set(ctx, key, i, 0); err != nil {
607607
t.Fatalf("Set: %v", err)
@@ -611,7 +611,7 @@ func TestCache_MainQueueEviction(t *testing.T) {
611611
}
612612

613613
// Insert more items to trigger eviction from Main queue
614-
for i := range 48 {
614+
for i := range 64 {
615615
key := fmt.Sprintf("key%d", i+100)
616616
if err := cache.Set(ctx, key, i+100, 0); err != nil {
617617
t.Fatalf("Set: %v", err)
@@ -620,8 +620,8 @@ func TestCache_MainQueueEviction(t *testing.T) {
620620
}
621621

622622
// Verify cache is at capacity
623-
if cache.Len() > 48 {
624-
t.Errorf("Cache length %d exceeds capacity 48", cache.Len())
623+
if cache.Len() > 64 {
624+
t.Errorf("Cache length %d exceeds capacity 64", cache.Len())
625625
}
626626
}
627627

cache_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,29 +544,29 @@ func TestCache_DeleteNonExistent(t *testing.T) {
544544

545545
func TestCache_EvictFromMain(t *testing.T) {
546546
ctx := context.Background()
547-
// Cache with capacity divisible by 16 shards (48 = 3 per shard)
548-
cache, err := New[int, int](ctx, WithMemorySize(48))
547+
// Cache with capacity divisible by 32 shards (64 = 2 per shard)
548+
cache, err := New[int, int](ctx, WithMemorySize(64))
549549
if err != nil {
550550
t.Fatalf("New: %v", err)
551551
}
552552
defer func() { _ = cache.Close() }() //nolint:errcheck // Test cleanup
553553

554554
// Fill small queue and promote items to main by accessing them twice
555-
for i := range 72 {
555+
for i := range 96 {
556556
_ = cache.Set(ctx, i, i, 0) //nolint:errcheck // Test fixture
557557
// Access immediately to promote to main
558558
_, _, _ = cache.Get(ctx, i) //nolint:errcheck // Exercising code path
559559
}
560560

561561
// Add more items to force eviction from main queue
562-
for i := range 48 {
562+
for i := range 64 {
563563
_ = cache.Set(ctx, i+100, i+100, 0) //nolint:errcheck // Test fixture
564564
_, _, _ = cache.Get(ctx, i+100) //nolint:errcheck // Exercising code path
565565
}
566566

567567
// Cache should not exceed capacity
568-
if cache.Len() > 48 {
569-
t.Errorf("cache length = %d; should not exceed 48", cache.Len())
568+
if cache.Len() > 64 {
569+
t.Errorf("cache length = %d; should not exceed 64", cache.Len())
570570
}
571571
}
572572

s3fifo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"time"
99
)
1010

11-
const numShards = 16
11+
const numShards = 32
1212

1313
// s3fifo implements the S3-FIFO eviction algorithm from SOSP'23 paper
1414
// "FIFO queues are all you need for cache eviction"

s3fifo_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,26 +477,26 @@ func TestS3FIFODetailed(t *testing.T) {
477477
}
478478

479479
func TestS3FIFO_Flush(t *testing.T) {
480-
cache := newS3FIFO[string, int](100)
480+
cache := newS3FIFO[string, int](1000)
481481

482-
// Add some items
483-
for i := range 50 {
482+
// Add some items (fewer than capacity to avoid eviction)
483+
for i := range 100 {
484484
cache.setToMemory(fmt.Sprintf("key%d", i), i, time.Time{})
485485
}
486486

487487
// Access some to promote to main queue
488-
for i := range 10 {
488+
for i := range 20 {
489489
cache.getFromMemory(fmt.Sprintf("key%d", i))
490490
}
491491

492-
if cache.memoryLen() != 50 {
493-
t.Errorf("cache length = %d; want 50", cache.memoryLen())
492+
if cache.memoryLen() != 100 {
493+
t.Errorf("cache length = %d; want 100", cache.memoryLen())
494494
}
495495

496496
// Flush
497497
removed := cache.flushMemory()
498-
if removed != 50 {
499-
t.Errorf("flushMemory removed %d items; want 50", removed)
498+
if removed != 100 {
499+
t.Errorf("flushMemory removed %d items; want 100", removed)
500500
}
501501

502502
// Cache should be empty
@@ -505,7 +505,7 @@ func TestS3FIFO_Flush(t *testing.T) {
505505
}
506506

507507
// All keys should be gone
508-
for i := range 50 {
508+
for i := range 100 {
509509
if _, ok := cache.getFromMemory(fmt.Sprintf("key%d", i)); ok {
510510
t.Errorf("key%d should not be found after flush", i)
511511
}

0 commit comments

Comments
 (0)