VictoriaMetrics/lib/storage/dedup_timing_test.go
Roman Khavronenko fd39eb2b2a
lib/storage: update dedup tests
* update misleading comments about preferring NaNs on intervals. NaNs
are only preferred on timestamp conflicts
* add conflicting timestamps to the benchmark test. Previously,
benchmark wasn't checking the timestamp conflict code branch. The
updated results after
c0fcfd6b97
are the following:
```
benchstat old.txt new.txt

goos: darwin
goarch: arm64
pkg: github.com/VictoriaMetrics/VictoriaMetrics/lib/storage
cpu: Apple M4 Pro
                                                       │   old.txt    │               new.txt                │
                                                       │    sec/op    │    sec/op     vs base                │
DeduplicateSamples/minScrapeInterval=3s-14               889.7n ± ∞ ¹   904.3n ± ∞ ¹       ~ (p=1.000 n=1) ²
DeduplicateSamples/minScrapeInterval=4s-14               735.9n ± ∞ ¹   748.7n ± ∞ ¹       ~ (p=1.000 n=1) ²
DeduplicateSamples/minScrapeInterval=10s-14              637.7n ± ∞ ¹   659.3n ± ∞ ¹       ~ (p=1.000 n=1) ²
DeduplicateSamplesDuringMerge/minScrapeInterval=3s-14    838.8n ± ∞ ¹   810.4n ± ∞ ¹       ~ (p=1.000 n=1) ²
DeduplicateSamplesDuringMerge/minScrapeInterval=4s-14    765.2n ± ∞ ¹   735.1n ± ∞ ¹       ~ (p=1.000 n=1) ²
DeduplicateSamplesDuringMerge/minScrapeInterval=10s-14   673.1n ± ∞ ¹   622.4n ± ∞ ¹       ~ (p=1.000 n=1) ²
geomean                                                  751.7n         741.0n        -1.42%
```

### Describe Your Changes

Please provide a brief description of the changes you made. Be as
specific as possible to help others understand the purpose and impact of
your modifications.

---
Signed-off-by: hagen1778 <roman@victoriametrics.com>
2024-12-18 22:38:36 +01:00

74 lines
2.3 KiB
Go

package storage
import (
"fmt"
"testing"
"time"
)
func BenchmarkDeduplicateSamples(b *testing.B) {
const blockSize = 8192
timestamps := make([]int64, blockSize)
values := make([]float64, blockSize)
for i := 0; i < len(timestamps); i++ {
isDuplicate := i%2 == 1
ts := int64(i) * 1e3
if isDuplicate {
ts = int64(i-1) * 1e3
}
timestamps[i] = ts
values[i] = float64(i)
}
for _, minScrapeInterval := range []time.Duration{3 * time.Second, 4 * time.Second, 10 * time.Second} {
b.Run(fmt.Sprintf("minScrapeInterval=%s", minScrapeInterval), func(b *testing.B) {
dedupInterval := minScrapeInterval.Milliseconds()
b.ReportAllocs()
b.SetBytes(blockSize)
b.RunParallel(func(pb *testing.PB) {
timestampsCopy := make([]int64, 0, blockSize)
valuesCopy := make([]float64, 0, blockSize)
for pb.Next() {
timestampsCopy := append(timestampsCopy[:0], timestamps...)
valuesCopy := append(valuesCopy[:0], values...)
ts, vs := DeduplicateSamples(timestampsCopy, valuesCopy, dedupInterval)
if len(ts) == 0 || len(vs) == 0 {
panic(fmt.Errorf("expecting non-empty results; got\nts=%v\nvs=%v", ts, vs))
}
}
})
})
}
}
func BenchmarkDeduplicateSamplesDuringMerge(b *testing.B) {
const blockSize = 8192
timestamps := make([]int64, blockSize)
values := make([]int64, blockSize)
for i := 0; i < len(timestamps); i++ {
isDuplicate := i%2 == 1
ts := int64(i) * 1e3
if isDuplicate {
ts = int64(i-1) * 1e3
}
timestamps[i] = ts
}
for _, minScrapeInterval := range []time.Duration{3 * time.Second, 4 * time.Second, 10 * time.Second} {
b.Run(fmt.Sprintf("minScrapeInterval=%s", minScrapeInterval), func(b *testing.B) {
dedupInterval := minScrapeInterval.Milliseconds()
b.ReportAllocs()
b.SetBytes(blockSize)
b.RunParallel(func(pb *testing.PB) {
timestampsCopy := make([]int64, 0, blockSize)
valuesCopy := make([]int64, 0, blockSize)
for pb.Next() {
timestampsCopy := append(timestampsCopy[:0], timestamps...)
valuesCopy := append(valuesCopy[:0], values...)
ts, vs := deduplicateSamplesDuringMerge(timestampsCopy, valuesCopy, dedupInterval)
if len(ts) == 0 || len(vs) == 0 {
panic(fmt.Errorf("expecting non-empty results; got\nts=%v\nvs=%v", ts, vs))
}
}
})
})
}
}