Skip to content

Commit 5d944b2

Browse files
add 2 more benchmarks
1 parent 85620fc commit 5d944b2

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

persist/sqlite/volumes_test.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13+
proto4 "go.sia.tech/core/rhp/v4"
1314
"go.sia.tech/core/types"
1415
"go.sia.tech/hostd/v2/host/contracts"
1516
"go.sia.tech/hostd/v2/host/storage"
@@ -997,6 +998,56 @@ func BenchmarkStoreSector(b *testing.B) {
997998
}
998999
}
9991000

1001+
func BenchmarkStoreSectorParallel(b *testing.B) {
1002+
const (
1003+
sectorsPerTiB uint64 = (1 << 40) / (1 << 22)
1004+
minSectors = 20 * sectorsPerTiB
1005+
)
1006+
1007+
sectors := max(minSectors, uint64(b.N))
1008+
1009+
log := zap.NewNop()
1010+
db, err := OpenDatabase(filepath.Join(b.TempDir(), "test.db"), log)
1011+
if err != nil {
1012+
b.Fatal(err)
1013+
}
1014+
defer db.Close()
1015+
1016+
_, err = addTestVolume(db, "test", sectors)
1017+
if err != nil {
1018+
b.Fatal(err)
1019+
}
1020+
1021+
for _, nThreads := range []int{5, 10, 50} {
1022+
b.Run(fmt.Sprintf("%d", nThreads), func(b *testing.B) {
1023+
b.ReportAllocs()
1024+
b.ReportMetric(float64(b.N), "sectors")
1025+
b.SetBytes(proto4.SectorSize)
1026+
1027+
var wg sync.WaitGroup
1028+
jobs := make(chan struct{})
1029+
for range nThreads {
1030+
wg.Add(1)
1031+
go func() {
1032+
defer wg.Done()
1033+
for range jobs {
1034+
err := db.StoreSector(frand.Entropy256(), func(loc storage.SectorLocation) error { return nil })
1035+
if err != nil {
1036+
b.Error(err)
1037+
return
1038+
}
1039+
}
1040+
}()
1041+
}
1042+
for i := 0; i < b.N; i++ {
1043+
jobs <- struct{}{}
1044+
}
1045+
close(jobs)
1046+
wg.Wait()
1047+
})
1048+
}
1049+
}
1050+
10001051
func BenchmarkReadSector(b *testing.B) {
10011052
const (
10021053
sectorsPerTiB uint64 = (1 << 40) / (1 << 22)
@@ -1036,3 +1087,61 @@ func BenchmarkReadSector(b *testing.B) {
10361087
}
10371088
}
10381089
}
1090+
1091+
func BenchmarkReadSectorParallel(b *testing.B) {
1092+
const (
1093+
sectorsPerTiB uint64 = (1 << 40) / (1 << 22)
1094+
minSectors = 20 * sectorsPerTiB
1095+
)
1096+
1097+
sectors := max(minSectors, uint64(b.N))
1098+
1099+
log := zap.NewNop()
1100+
db, err := OpenDatabase(filepath.Join(b.TempDir(), "test.db"), log)
1101+
if err != nil {
1102+
b.Fatal(err)
1103+
}
1104+
defer db.Close()
1105+
1106+
_, err = addTestVolume(db, "test", sectors)
1107+
if err != nil {
1108+
b.Fatal(err)
1109+
}
1110+
1111+
roots := make([]types.Hash256, 50)
1112+
for i := range roots {
1113+
err = db.StoreSector(roots[i], func(loc storage.SectorLocation) error { return nil })
1114+
if err != nil {
1115+
b.Fatal(err)
1116+
}
1117+
}
1118+
1119+
for _, nThreads := range []int{5, 10, 50} {
1120+
b.Run(fmt.Sprintf("%d", nThreads), func(b *testing.B) {
1121+
b.ReportAllocs()
1122+
b.ReportMetric(float64(b.N), "sectors")
1123+
b.SetBytes(proto4.SectorSize)
1124+
1125+
var wg sync.WaitGroup
1126+
jobs := make(chan int)
1127+
for i := range nThreads {
1128+
wg.Add(1)
1129+
go func() {
1130+
defer wg.Done()
1131+
for range jobs {
1132+
_, err := db.SectorLocation(roots[i])
1133+
if err != nil {
1134+
b.Error(err)
1135+
return
1136+
}
1137+
}
1138+
}()
1139+
}
1140+
for i := 0; i < b.N; i++ {
1141+
jobs <- i % len(roots)
1142+
}
1143+
close(jobs)
1144+
wg.Wait()
1145+
})
1146+
}
1147+
}

0 commit comments

Comments
 (0)