mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Benchmarks refactor and include benchmark with dataset
This commit is contained in:
parent
c62a862aa6
commit
6afb30a06f
|
@ -1,6 +1,7 @@
|
||||||
package remote
|
package remote
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -46,83 +47,37 @@ func TestCompressions(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCompressions_V11(b *testing.B) {
|
|
||||||
data := makeUncompressedReducedWriteRequestBenchData(b)
|
|
||||||
bc := []struct {
|
|
||||||
name string
|
|
||||||
algo CompAlgorithm
|
|
||||||
}{
|
|
||||||
{"Snappy", Snappy},
|
|
||||||
{"SnappyAlt", SnappyAlt},
|
|
||||||
{"S2", S2},
|
|
||||||
{"ZstdFast", ZstdFast},
|
|
||||||
{"ZstdDefault", ZstdDefault},
|
|
||||||
{"ZstdBestComp", ZstdBestComp},
|
|
||||||
{"Lzw", Lzw},
|
|
||||||
{"FlateFast", FlateFast},
|
|
||||||
{"FlateComp", FlateComp},
|
|
||||||
{"BrotliFast", BrotliFast},
|
|
||||||
// {"BrotliComp", BrotliComp},
|
|
||||||
{"BrotliDefault", BrotliDefault},
|
|
||||||
}
|
|
||||||
comps := make(map[CompAlgorithm]Compression)
|
|
||||||
decomps := make(map[CompAlgorithm]Compression)
|
|
||||||
for _, c := range bc {
|
|
||||||
UseAlgorithm = c.algo
|
|
||||||
comp := createComp()
|
|
||||||
decomp := createComp()
|
|
||||||
comps[c.algo] = comp
|
|
||||||
decomps[c.algo] = decomp
|
|
||||||
// warmup
|
|
||||||
for i := 0; i < 2; i++ {
|
|
||||||
compressed, err := comp.Compress(data)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = decomp.Decompress(compressed)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range bc {
|
|
||||||
b.Run(c.name, func(b *testing.B) {
|
|
||||||
comp := comps[c.algo]
|
|
||||||
decomp := decomps[c.algo]
|
|
||||||
|
|
||||||
totalSize := 0
|
|
||||||
compTime := 0
|
|
||||||
decompTime := 0
|
|
||||||
rate := 0.0
|
|
||||||
var start time.Time
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
start = time.Now()
|
|
||||||
res, err := comp.Compress(data)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatal(err)
|
|
||||||
}
|
|
||||||
compTime += int(time.Since(start))
|
|
||||||
totalSize += len(res)
|
|
||||||
rate += float64(len(data)) / float64(len(res))
|
|
||||||
|
|
||||||
start = time.Now()
|
|
||||||
_, err = decomp.Decompress(res)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatal(err)
|
|
||||||
}
|
|
||||||
decompTime += int(time.Since(start))
|
|
||||||
}
|
|
||||||
b.ReportMetric(float64(totalSize)/float64(b.N), "compressedSize/op")
|
|
||||||
b.ReportMetric(float64(compTime)/float64(b.N), "nsCompress/op")
|
|
||||||
b.ReportMetric(float64(decompTime)/float64(b.N), "nsDecompress/op")
|
|
||||||
b.ReportMetric(rate/float64(b.N), "compressionX/op")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkCompressions_V1(b *testing.B) {
|
func BenchmarkCompressions_V1(b *testing.B) {
|
||||||
|
// Synthetic data, attempts to be representative
|
||||||
data := makeUncompressedWriteRequestBenchData(b)
|
data := makeUncompressedWriteRequestBenchData(b)
|
||||||
|
benchmarkCompressionsForData(b, [][]byte{data})
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkCompressions_V11(b *testing.B) {
|
||||||
|
// Synthetic data, attempts to be representative
|
||||||
|
data := makeUncompressedWriteRequestBenchData(b)
|
||||||
|
benchmarkCompressionsForData(b, [][]byte{data})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Needs the dataset to be present in /home/nicolas/rw11data/v11_raw/
|
||||||
|
func BenchmarkCompressions_V11_FileDataSet(b *testing.B) {
|
||||||
|
datas := readAllFiles("/home/nicolas/rw11data/v11_raw/")
|
||||||
|
if len(datas) != 10 {
|
||||||
|
b.Fatal("unexpected number of files")
|
||||||
|
}
|
||||||
|
benchmarkCompressionsForData(b, datas)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Needs the dataset to be present in /home/nicolas/rw11data/v1_raw/
|
||||||
|
func BenchmarkCompressions_V1_FileDataSet(b *testing.B) {
|
||||||
|
datas := readAllFiles("/home/nicolas/rw11data/v1_raw/")
|
||||||
|
if len(datas) != 10 {
|
||||||
|
b.Fatal("unexpected number of files")
|
||||||
|
}
|
||||||
|
benchmarkCompressionsForData(b, datas)
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkCompressionsForData(b *testing.B, datas [][]byte) {
|
||||||
bc := []struct {
|
bc := []struct {
|
||||||
name string
|
name string
|
||||||
algo CompAlgorithm
|
algo CompAlgorithm
|
||||||
|
@ -135,10 +90,11 @@ func BenchmarkCompressions_V1(b *testing.B) {
|
||||||
{"ZstdBestComp", ZstdBestComp},
|
{"ZstdBestComp", ZstdBestComp},
|
||||||
{"Lzw", Lzw},
|
{"Lzw", Lzw},
|
||||||
{"FlateFast", FlateFast},
|
{"FlateFast", FlateFast},
|
||||||
|
{"FlateDefault", FlateDefault},
|
||||||
{"FlateComp", FlateComp},
|
{"FlateComp", FlateComp},
|
||||||
{"BrotliFast", BrotliFast},
|
{"BrotliFast", BrotliFast},
|
||||||
// {"BrotliComp", BrotliComp},
|
|
||||||
{"BrotliDefault", BrotliDefault},
|
{"BrotliDefault", BrotliDefault},
|
||||||
|
// {"BrotliComp", BrotliComp},
|
||||||
}
|
}
|
||||||
comps := make(map[CompAlgorithm]Compression)
|
comps := make(map[CompAlgorithm]Compression)
|
||||||
decomps := make(map[CompAlgorithm]Compression)
|
decomps := make(map[CompAlgorithm]Compression)
|
||||||
|
@ -150,6 +106,7 @@ func BenchmarkCompressions_V1(b *testing.B) {
|
||||||
decomps[c.algo] = decomp
|
decomps[c.algo] = decomp
|
||||||
// warmup
|
// warmup
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
|
for _, data := range datas {
|
||||||
compressed, err := comp.Compress(data)
|
compressed, err := comp.Compress(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
@ -160,6 +117,7 @@ func BenchmarkCompressions_V1(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, c := range bc {
|
for _, c := range bc {
|
||||||
b.Run(c.name, func(b *testing.B) {
|
b.Run(c.name, func(b *testing.B) {
|
||||||
|
@ -167,11 +125,12 @@ func BenchmarkCompressions_V1(b *testing.B) {
|
||||||
decomp := decomps[c.algo]
|
decomp := decomps[c.algo]
|
||||||
|
|
||||||
totalSize := 0
|
totalSize := 0
|
||||||
|
totalRawSize := 0
|
||||||
compTime := 0
|
compTime := 0
|
||||||
decompTime := 0
|
decompTime := 0
|
||||||
rate := 0.0
|
|
||||||
var start time.Time
|
var start time.Time
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
for _, data := range datas {
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
res, err := comp.Compress(data)
|
res, err := comp.Compress(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -179,8 +138,7 @@ func BenchmarkCompressions_V1(b *testing.B) {
|
||||||
}
|
}
|
||||||
compTime += int(time.Since(start))
|
compTime += int(time.Since(start))
|
||||||
totalSize += len(res)
|
totalSize += len(res)
|
||||||
rate += float64(len(data)) / float64(len(res))
|
totalRawSize += len(data)
|
||||||
|
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
_, err = decomp.Decompress(res)
|
_, err = decomp.Decompress(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -188,10 +146,29 @@ func BenchmarkCompressions_V1(b *testing.B) {
|
||||||
}
|
}
|
||||||
decompTime += int(time.Since(start))
|
decompTime += int(time.Since(start))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
b.ReportMetric(float64(totalSize)/float64(b.N), "compressedSize/op")
|
b.ReportMetric(float64(totalSize)/float64(b.N), "compressedSize/op")
|
||||||
b.ReportMetric(float64(compTime)/float64(b.N), "nsCompress/op")
|
b.ReportMetric(float64(compTime)/float64(b.N), "nsCompress/op")
|
||||||
b.ReportMetric(float64(decompTime)/float64(b.N), "nsDecompress/op")
|
b.ReportMetric(float64(decompTime)/float64(b.N), "nsDecompress/op")
|
||||||
b.ReportMetric(rate/float64(b.N), "compressionX/op")
|
rate := float64(totalRawSize) / float64(totalSize)
|
||||||
|
b.ReportMetric(rate, "compressionX")
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readAllFiles(dir string) (res [][]byte) {
|
||||||
|
files, err := os.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
filename := dir + file.Name()
|
||||||
|
data, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
res = append(res, data)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue