#363·ristretto

[问题]: 为什么 Ristretto 速度如此慢, 击中率如此之低?

作者: maypok86创建于 2023年11月15日更新于 2026年6月24日
标签kind/questionStale

Question. Hi, I am currently writing a similar package and tried to compare my implementation https://GitHub.com/maypok86/otter with Ristretto. In the end, I found that Ristretto loses very badly (about 5-7 times) and has a hit ratio on most traces around zero. I can roughly understand why there is a terrible loss in speed (Ristretto even though it says it is contention-free, it actually locks its shards very often, which ends up not giving enough performance to fight Otter). I attached benchmarks with the best cache libraries at the moment. goos: darwin goarch: arm64 pkg: GitHub.com/maypok86/benchmarks BenchmarkCache/Zipf_Otter_reads=100%,writes=0%-10 21643555 46.95 ns/op 1 B/op 0 allocs/op BenchmarkCache/Zipf_Theine_reads=100%,writes=0%-10 12177036 97.41 ns/op 0 B/op 0 allocs/op BenchmarkCache/Zipf_Ristretto_reads=100%,writes=0%-10 20823691 54.00 ns/op 16 B/op 1 allocs/op BenchmarkCache/Zipf_Otter_reads=75%,writes=25%-10 17760416 66.58 ns/op 6 B/op 0 allocs/op BenchmarkCache/Zipf_Theine_reads=75%,writes=25%-10 2540319 462.3 ns/op 0 B/op 0 allocs/op BenchmarkCache/Zipf_Ristretto_reads=75%,writes=25%-10 2442692 464.9 ns/op 51 B/op 2 allocs/op BenchmarkCache/Zipf_Otter_reads=50%,writes=50%-10 13647469 78.17 ns/op 11 B/op 0 allocs/op BenchmarkCache/Zipf_Theine_reads=50%,writes=50%-10 2298838 537.8 ns/op 0 B/op 0 allocs/op BenchmarkCache/Zipf_Ristretto_reads=50%,writes=50%-10 2603936 444.1 ns/op 72 B/op 2 allocs/op BenchmarkCache/Zipf_Otter_reads=25%,writes=75%-10 10211748 100.6 ns/op 16 B/op 0 allocs/op BenchmarkCache/Zipf_Theine_reads=25%,writes=75%-10 2140611 563.8 ns/op 0 B/op 0 allocs/op BenchmarkCache/Zipf_Ristretto_reads=25%,writes=75%-10 2401822 571.2 ns/op 102 B/op 3 allocs/op BenchmarkCache/Zipf_Otter_reads=0%,writes=100%-10 19658750 57.54 ns/op 0 B/op 0 allocs/op BenchmarkCache/Zipf_Theine_reads=0%,writes=100%-10 1958818 656.7 ns/op 0 B/op 0 allocs/op BenchmarkCache/Zipf_Ristretto_reads=0%,writes=100%-10 2606988 450.6 ns/op 124 B/op 3 allocs/op PASS ok GitHub.com/maypok86/benchmarks 171.538s

内容来源: dgraph-io/ristretto