Skip to content

Commit 5aa709d

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
crazy performance tuning?
1 parent 015a7ba commit 5aa709d

File tree

7 files changed

+1568
-354
lines changed

7 files changed

+1568
-354
lines changed

Makefile

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.PHONY: test lint bench benchmark clean
1+
.PHONY: test lint bench benchmark benchmark-quick benchmark-throughput benchmark-hitrate benchmark-external benchmark-suite clean
22

33
test:
44
@echo "Running tests in all modules..."
5-
@find . -name go.mod -execdir go test -v -race -cover -run '^Test' ./... \;
5+
@find . -name go.mod -execdir go test -v -race -cover -short -run '^Test' ./... \;
66

77
lint:
88
go vet ./...
@@ -12,8 +12,33 @@ lint:
1212
bench:
1313
go test -bench=. -benchmem
1414

15-
benchmark:
16-
@cd benchmarks && go test -run=TestBenchmarkSuite -v -timeout=600s
15+
# Run all benchmarks (shortest to longest)
16+
benchmark: benchmark-quick benchmark-throughput benchmark-external benchmark-hitrate benchmark-suite
17+
18+
# Quick hit ratio comparison for tuning (~3s)
19+
benchmark-quick:
20+
@echo "=== Quick Hit Rate Comparison ==="
21+
@cd benchmarks && go test -run=TestQuickHitRate -v
22+
23+
# Parallel throughput benchmarks (~30s)
24+
benchmark-throughput:
25+
@echo "=== Parallel Throughput Benchmarks ==="
26+
@cd benchmarks && go test -bench=BenchmarkThroughput -benchmem -cpu=1,4,8,16
27+
28+
# External benchmark comparison (~10s)
29+
benchmark-external:
30+
@echo "=== External Benchmark Comparison (go-cache-benchmark style) ==="
31+
@cd benchmarks && go test -run=TestExternalBenchmark -v
32+
33+
# Hit ratio benchmarks with trace patterns (~2min)
34+
benchmark-hitrate:
35+
@echo "=== Trace-Based Hit Ratio Benchmarks ==="
36+
@cd benchmarks && go test -run=TestTraceHitRate -v -timeout=900s
37+
38+
# Full benchmark suite (~5min)
39+
benchmark-suite:
40+
@echo "=== Full Benchmark Suite ==="
41+
@cd benchmarks && go test -run=TestBenchmarkSuite -v -timeout=900s
1742

1843
clean:
1944
go clean -testcache

benchmarks/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
This directory contains comparison benchmarks against popular Go cache libraries.
44

5+
## Attribution
6+
7+
The throughput and hit ratio benchmarks are inspired by and adapted from:
8+
- [go-cache-benchmark-plus](https://github.com/Yiling-J/go-cache-benchmark-plus) by Yiling-J (theine-go author)
9+
- Original benchmark framework designed for comparing cache implementations
10+
511
## ⚠️ Important Disclaimers
612

713
### Cherrypicked Benchmarks
@@ -41,6 +47,39 @@ Other libraries require manual save/load of the entire cache, which:
4147

4248
## Running Benchmarks
4349

50+
### Parallel Throughput (go-cache-benchmark-plus style)
51+
52+
```bash
53+
# Run with varying CPU counts
54+
go test -bench=BenchmarkThroughput -benchmem -cpu=1,4,8,16
55+
56+
# Just Get operations
57+
go test -bench=BenchmarkThroughputGetParallel -benchmem -cpu=16
58+
59+
# Just Set operations
60+
go test -bench=BenchmarkThroughputSetParallel -benchmem -cpu=16
61+
62+
# Hot key contention test
63+
go test -bench=BenchmarkThroughputGetSingle -benchmem -cpu=16
64+
```
65+
66+
### Hit Ratio Tests (trace-based patterns)
67+
68+
```bash
69+
# Quick comparison for tuning
70+
go test -run=TestQuickHitRate -v
71+
72+
# Full trace-based hit ratio tests
73+
go test -run=TestTraceHitRate -v
74+
75+
# Individual trace patterns
76+
go test -run=TestTraceHitRateZipf -v # Zipf distribution
77+
go test -run=TestTraceHitRateDatabase -v # Database/ERP pattern
78+
go test -run=TestTraceHitRateSearch -v # Search engine pattern
79+
go test -run=TestTraceHitRateScan -v # Scan resistance test
80+
go test -run=TestTraceHitRateMixed -v # Mixed GET/SET workload
81+
```
82+
4483
### Speed Comparison
4584

4685
```bash
@@ -64,6 +103,8 @@ Runs the complete benchmark comparison including hit rates, latency, and concurr
64103
## Benchmark Files
65104

66105
- `benchmark_test.go` - Speed, hit rate, and throughput benchmarks across libraries
106+
- `throughput_test.go` - Parallel throughput benchmarks (go-cache-benchmark-plus style)
107+
- `hitrate_trace_test.go` - Hit ratio benchmarks using synthetic trace patterns
67108

68109
## Interpreting Results
69110

0 commit comments

Comments
 (0)