2020-02-23 12:35:47 +01:00
|
|
|
package persistentqueue
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2020-12-08 19:49:32 +01:00
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
2020-02-23 12:35:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkFastQueueThroughputSerial(b *testing.B) {
|
|
|
|
const iterationsCount = 10
|
|
|
|
for _, blockSize := range []int{1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6} {
|
|
|
|
block := make([]byte, blockSize)
|
|
|
|
b.Run(fmt.Sprintf("block-size-%d", blockSize), func(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(int64(blockSize) * iterationsCount)
|
|
|
|
path := fmt.Sprintf("bench-fast-queue-throughput-serial-%d", blockSize)
|
|
|
|
mustDeleteDir(path)
|
2023-11-24 13:42:11 +01:00
|
|
|
fq := MustOpenFastQueue(path, "foobar", iterationsCount*2, 0, false)
|
2020-02-23 12:35:47 +01:00
|
|
|
defer func() {
|
|
|
|
fq.MustClose()
|
|
|
|
mustDeleteDir(path)
|
|
|
|
}()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2023-11-25 10:31:30 +01:00
|
|
|
writeReadIterationFastQueue(fq, block, iterationsCount)
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkFastQueueThroughputConcurrent(b *testing.B) {
|
|
|
|
const iterationsCount = 10
|
|
|
|
for _, blockSize := range []int{1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6} {
|
|
|
|
block := make([]byte, blockSize)
|
|
|
|
b.Run(fmt.Sprintf("block-size-%d", blockSize), func(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(int64(blockSize) * iterationsCount)
|
|
|
|
path := fmt.Sprintf("bench-fast-queue-throughput-concurrent-%d", blockSize)
|
|
|
|
mustDeleteDir(path)
|
2023-11-24 13:42:11 +01:00
|
|
|
fq := MustOpenFastQueue(path, "foobar", iterationsCount*cgroup.AvailableCPUs()*2, 0, false)
|
2020-02-23 12:35:47 +01:00
|
|
|
defer func() {
|
|
|
|
fq.MustClose()
|
|
|
|
mustDeleteDir(path)
|
|
|
|
}()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
2023-11-25 10:31:30 +01:00
|
|
|
writeReadIterationFastQueue(fq, block, iterationsCount)
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-25 10:31:30 +01:00
|
|
|
func writeReadIterationFastQueue(fq *FastQueue, block []byte, iterationsCount int) {
|
2020-02-23 12:35:47 +01:00
|
|
|
for i := 0; i < iterationsCount; i++ {
|
2023-11-25 10:31:30 +01:00
|
|
|
if !fq.TryWriteBlock(block) {
|
|
|
|
panic(fmt.Errorf("TryWriteBlock must return true"))
|
2023-11-24 13:42:11 +01:00
|
|
|
}
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|
|
|
|
var ok bool
|
|
|
|
bb := bbPool.Get()
|
|
|
|
for i := 0; i < iterationsCount; i++ {
|
|
|
|
bb.B, ok = fq.MustReadBlock(bb.B[:0])
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Errorf("unexpected ok=false"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bbPool.Put(bb)
|
|
|
|
}
|