Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptive LRU window #55

Merged
merged 32 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0ff87a9
use single LRU as window
Yiling-J Oct 22, 2024
111bd4d
minor change
Yiling-J Oct 22, 2024
fbd07f9
refactor and add some policy tests
Yiling-J Oct 24, 2024
cc1738f
fix tests
Yiling-J Oct 24, 2024
42d7107
fix tests
Yiling-J Oct 24, 2024
ae102f1
fix cost update
Yiling-J Oct 24, 2024
f33e813
fix demote bug
Yiling-J Oct 24, 2024
7bcd43f
fix demote not run
Yiling-J Oct 24, 2024
8dd0066
add sketch resize test
Yiling-J Oct 24, 2024
24263de
fix adaptive should climb check
Yiling-J Oct 24, 2024
fcc1db0
fix tlfu tests
Yiling-J Oct 24, 2024
95e9bc3
improve policy update schedule
Yiling-J Oct 24, 2024
ee71aa5
fix test
Yiling-J Oct 24, 2024
523ef84
sketch use uint64 counter
Yiling-J Oct 24, 2024
1cd742d
remove atomic from list
Yiling-J Oct 24, 2024
fc81f05
add hash check to policy read if sync pool enabled
Yiling-J Oct 24, 2024
a11e49d
update test name
Yiling-J Oct 25, 2024
390cadb
update ci
Yiling-J Oct 25, 2024
f98fcd1
update ci
Yiling-J Oct 25, 2024
039a0b7
update hit ratio benchmark results
Yiling-J Oct 25, 2024
27771de
add twitter cluster52 sample10 result
Yiling-J Oct 26, 2024
6548371
fix flaky test
Yiling-J Oct 26, 2024
25d3ce5
fix low hit ratio climb not run
Yiling-J Oct 26, 2024
c4b1967
remove wrong rehash function
Yiling-J Oct 27, 2024
b6161d5
minor improvement
Yiling-J Oct 28, 2024
4cfffb7
update hit ratio bench results
Yiling-J Oct 28, 2024
d40c55f
fix estimated size
Yiling-J Oct 28, 2024
5fc37f1
fix race when using entry pool
Yiling-J Oct 28, 2024
32c6708
add some comments to policy test
Yiling-J Oct 29, 2024
4ccae57
fix policy updateCost
Yiling-J Oct 29, 2024
0ecf1cf
fix window evict test
Yiling-J Oct 29, 2024
252cbf8
fix wrong weightedsize caused by event race
Yiling-J Oct 29, 2024
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
12 changes: 6 additions & 6 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3

test-race-nopool:
name: test-race-nopool
test-correctness-nopool:
name: test-correctness-nopool
strategy:
matrix:
go: ["1.23.x"]
Expand All @@ -59,10 +59,10 @@ jobs:
- uses: actions/checkout@v2

- name: Test
run: go test ./... -run=TestCacheRace_NoPool -count=1 -race
run: go test ./... -run=TestCacheCorrectness_NoPool -count=1 -race

test-race-pool:
name: test-race-pool
test-correctness-pool:
name: test-correctness-pool
strategy:
matrix:
go: ["1.23.x"]
Expand All @@ -76,7 +76,7 @@ jobs:
- uses: actions/checkout@v2

- name: Test
run: go test ./... -run=TestCacheRace_EntryPool -count=1
run: go test ./... -run=TestCacheCorrectness_EntryPool -count=1

test-os:
name: test-os
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.PHONY: test test-race-pool test-race-nopool testx lint bench cover

test:
go test -race -skip=TestCacheRace_ ./...
go test -race -skip=TestCacheCorrectness_ ./...

test-race-pool:
go test ./... -run=TestCacheRace_EntryPool -count=1
test-correct-pool:
go test ./... -run=TestCacheCorrectness_EntryPool -count=1

test-race-nopool:
go test ./... -run=TestCacheRace_NoPool -count=1 -race
test-correct-nopool:
go test ./... -run=TestCacheCorrectness_NoPool -count=1 -race

testx:
go test ./... -v -failfast
Expand All @@ -16,5 +16,5 @@ lint:
golangci-lint run

cover:
go test -timeout 2000s -race -coverprofile=cover.out -coverpkg=./... -skip=TestCacheRace_ ./...
go test -timeout 2000s -race -coverprofile=cover.out -coverpkg=./... -skip=TestCacheCorrectness_ ./...
go tool cover -html=cover.out -o cover.html
Binary file modified benchmarks/results/ds1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added benchmarks/results/mix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified benchmarks/results/oltp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified benchmarks/results/s3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added benchmarks/results/twitter-c52s10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added benchmarks/results/wikicdn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified benchmarks/results/zipf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func (c *Cache[K, V]) Stats() Stats {
return c.store.Stats()
}

// Wait write buffer sync to policy.
func (c *Cache[K, V]) Wait() {
c.store.Wait()
}

type LoadingCache[K comparable, V any] struct {
store *internal.LoadingStore[K, V]
}
Expand Down Expand Up @@ -157,6 +162,11 @@ func (c *LoadingCache[K, V]) Stats() Stats {
return c.store.Stats()
}

// Wait write buffer sync to policy.
func (c *LoadingCache[K, V]) Wait() {
c.store.Wait()
}

// Close closes all goroutines created by cache.
func (c *LoadingCache[K, V]) Close() {
c.store.Close()
Expand Down
21 changes: 9 additions & 12 deletions cache_race_test.go → cache_correctness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ func getSet(t *testing.T, entrypool bool) {

require.Equal(t, client.Len(), int(di.TotalCount()))
require.True(t, di.TotalWeight() <= int64(size+size/10))
require.True(t, di.TotalWeight() >= int64(size-15))
require.Equal(t, di.TotalWeight(), di.WeightedSize)
require.Equal(t, di.WindowWeight, di.WindowWeightField)
require.Equal(t, di.ProbationWeight, di.ProbationWeightField)
require.Equal(t, di.ProtectedWeight, di.ProtectedWeightField)

for i := 0; i < len(di.QueueWeight); i++ {
require.Equal(t, di.QueueWeight[i], di.QueueWeightField[i])
}

client.store.RangeEntry(func(entry *internal.Entry[uint64, uint64]) {
require.Equal(t, entry.Weight(), entry.PolicyWeight(), entry.Position())
})
Expand All @@ -80,11 +79,11 @@ func getSet(t *testing.T, entrypool bool) {
}
}

func TestCacheRace_EntryPool_GetSet(t *testing.T) {
func TestCacheCorrectness_EntryPool_GetSet(t *testing.T) {
getSet(t, true)

}
func TestCacheRace_NoPool_GetSet(t *testing.T) {
func TestCacheCorrectness_NoPool_GetSet(t *testing.T) {
getSet(t, false)

}
Expand Down Expand Up @@ -138,13 +137,11 @@ func getSetDeleteExpire(t *testing.T, entrypool bool) {

require.Equal(t, client.Len(), int(di.TotalCount()))
require.True(t, di.TotalWeight() <= int64(size+size/10))
require.Equal(t, di.TotalWeight(), di.WeightedSize)
require.Equal(t, di.WindowWeight, di.WindowWeightField)
require.Equal(t, di.ProbationWeight, di.ProbationWeightField)
require.Equal(t, di.ProtectedWeight, di.ProtectedWeightField)

for i := 0; i < len(di.QueueWeight); i++ {
require.Equal(t, di.QueueWeight[i], di.QueueWeightField[i])
}

client.store.RangeEntry(func(entry *internal.Entry[uint64, uint64]) {
require.Equal(t, entry.Weight(), entry.PolicyWeight(), entry.Position())
})
Expand All @@ -154,10 +151,10 @@ func getSetDeleteExpire(t *testing.T, entrypool bool) {
}
}

func TestCacheRace_EntryPool_GetSetDeleteExpire(t *testing.T) {
func TestCacheCorrectness_EntryPool_GetSetDeleteExpire(t *testing.T) {
getSetDeleteExpire(t, true)
}

func TestCacheRace_NoPool_GetSetDeleteExpire(t *testing.T) {
func TestCacheCorrectness_NoPool_GetSetDeleteExpire(t *testing.T) {
getSetDeleteExpire(t, false)
}
Loading
Loading