@@ -10,6 +10,7 @@ import (
10
10
"testing"
11
11
"time"
12
12
13
+ proto4 "go.sia.tech/core/rhp/v4"
13
14
"go.sia.tech/core/types"
14
15
"go.sia.tech/hostd/v2/host/contracts"
15
16
"go.sia.tech/hostd/v2/host/storage"
@@ -997,6 +998,56 @@ func BenchmarkStoreSector(b *testing.B) {
997
998
}
998
999
}
999
1000
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
+
1000
1051
func BenchmarkReadSector (b * testing.B ) {
1001
1052
const (
1002
1053
sectorsPerTiB uint64 = (1 << 40 ) / (1 << 22 )
@@ -1036,3 +1087,61 @@ func BenchmarkReadSector(b *testing.B) {
1036
1087
}
1037
1088
}
1038
1089
}
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