@@ -28,6 +28,8 @@ func main() {
28
28
objectCount := os .Getenv ("MAX_OBJECTS" )
29
29
testDuration := os .Getenv ("TEST_DURATION" )
30
30
useSSL := os .Getenv ("USE_SSL" )
31
+ readSizeKB := os .Getenv ("READ_SIZE_KB" )
32
+ readBufferSizeKB := os .Getenv ("READ_BUFFER_SIZE_KB" )
31
33
32
34
if accessKeyID == "" || secretKey == "" {
33
35
slog .Error ("S3_ACCESS_KEY_ID and S3_ACCESS_KEY_SECRET_KEY are required to run" )
@@ -90,9 +92,43 @@ func main() {
90
92
}
91
93
}
92
94
95
+ // 16KiB by default
96
+ readSize := int64 (16 * 1024 )
97
+ if readSizeKB != "" {
98
+ val , err := strconv .Atoi (readSizeKB )
99
+ if err != nil {
100
+ slog .Error ("failed to parse READ_SIZE_KB" , "error" , err )
101
+
102
+ os .Exit (1 )
103
+ }
104
+
105
+ readSize = int64 (val * 1024 )
106
+ }
107
+
108
+ // 32KiB by default
109
+ readBufferSize := 32 * 1024
110
+ if readBufferSizeKB != "" {
111
+ val , err := strconv .Atoi (readBufferSizeKB )
112
+ if err != nil {
113
+ slog .Error ("failed to parse READ_BUFFER_SIZE_KB" , "error" , err )
114
+
115
+ os .Exit (1 )
116
+ }
117
+
118
+ readBufferSize = val * 1024
119
+ }
120
+
93
121
ctx , cancel := context .WithCancel (context .Background ())
94
122
transport := cleanhttp .DefaultPooledTransport ()
95
123
124
+ // Modify some defaults to be more performant
125
+ transport .MaxConnsPerHost = threads
126
+ transport .DisableCompression = true
127
+
128
+ // Our test only reads so just bump both buffers
129
+ transport .ReadBufferSize = readBufferSize
130
+ transport .WriteBufferSize = readBufferSize
131
+
96
132
s3Client , err := minio .New (endpoint , & minio.Options {
97
133
Creds : credentials .NewStaticV4 (accessKeyID , secretKey , "" ),
98
134
Secure : ssl ,
@@ -137,10 +173,13 @@ func main() {
137
173
Objects : objects ,
138
174
ObjectSizes : sizes ,
139
175
S3Client : s3Client ,
176
+ BlockSize : readSize ,
140
177
}
141
178
142
179
start := time .Now ().UTC ()
143
180
181
+ slog .Info ("starting test" )
182
+
144
183
for i := range threads {
145
184
wg .Add (1 )
146
185
go func () {
@@ -160,17 +199,22 @@ func main() {
160
199
161
200
aggregatedBytesRead := 0
162
201
aggregatedRequestsSent := 0
163
- var averageTTLB int64
202
+ var (
203
+ averageTTLB int64
204
+ averageTestTime int64
205
+ )
164
206
165
207
for range threads {
166
208
result := <- resultChan
167
209
168
210
aggregatedBytesRead += int (result .TotalBytesRead )
169
211
aggregatedRequestsSent += int (result .TotalRequestsSent )
170
212
averageTTLB += result .TotalTTLBMS
213
+ averageTestTime += result .TotalTestTimeMS
171
214
}
172
215
173
216
averageTTLB = averageTTLB / int64 (aggregatedRequestsSent )
217
+ averageTestTime = averageTestTime / int64 (aggregatedRequestsSent )
174
218
175
219
timeSpent := time .Since (start )
176
220
@@ -181,12 +225,14 @@ func main() {
181
225
t .AppendRow (table.Row {"Total Bytes Read" , fmt .Sprintf ("%d" , aggregatedBytesRead )})
182
226
t .AppendRow (table.Row {"Total Requests Sent" , fmt .Sprintf ("%d" , aggregatedRequestsSent )})
183
227
t .AppendRow (table.Row {"Average TTLB" , fmt .Sprintf ("%d" , averageTTLB )})
228
+ t .AppendRow (table.Row {"Average Test Time" , fmt .Sprintf ("%d" , averageTestTime )})
184
229
185
230
t .Render ()
186
231
}
187
232
188
233
type testParams struct {
189
234
Bucket string
235
+ BlockSize int64
190
236
RNG * rand.Rand
191
237
Objects []string
192
238
ObjectSizes []int64
@@ -196,40 +242,38 @@ type testParams struct {
196
242
type testResult struct {
197
243
TotalBytesRead int64
198
244
TotalRequestsSent int64
245
+ TotalTestTimeMS int64
199
246
TotalTTLBMS int64
200
247
}
201
248
202
249
func runTest (ctx context.Context , params * testParams , id int ) * testResult {
203
250
ll := slog .With ("ID" , id )
204
251
205
- ll .Info ("starting test" )
206
-
207
252
result := & testResult {}
208
253
209
254
testCtx := context .Background ()
210
255
211
256
for {
212
257
select {
213
258
case <- ctx .Done ():
214
- ll .Info ("context cancelled, stopping test" )
215
-
216
259
return result
217
260
default :
261
+ testStart := time .Now ().UTC ()
218
262
// Get our random object
219
263
randObjIndex := params .RNG .Int () % len (params .Objects )
220
264
obj := params .Objects [randObjIndex ]
221
265
size := params .ObjectSizes [randObjIndex ]
222
266
223
267
// Get a random 16KiB offset to read
224
- maxOffset := size / ( 16 * 1024 )
268
+ maxOffset := size / params . BlockSize
225
269
randObjOffset := params .RNG .Int () % int (maxOffset )
226
270
227
- rangeStart := int64 (randObjOffset * ( 16 * 1024 ))
228
- rangeEnd := min (int64 (( rangeStart + ( 16 * 1024 )) ), size )
271
+ rangeStart := int64 (randObjOffset ) * params . BlockSize
272
+ rangeEnd := min (( rangeStart + params . BlockSize ), size )
229
273
230
274
result .TotalRequestsSent ++
231
275
232
- start := time .Now ().UTC ()
276
+ reqStart := time .Now ().UTC ()
233
277
234
278
reqOpts := minio.GetObjectOptions {}
235
279
reqOpts .SetRange (rangeStart , rangeEnd )
@@ -246,7 +290,9 @@ func runTest(ctx context.Context, params *testParams, id int) *testResult {
246
290
resp .Close ()
247
291
248
292
result .TotalBytesRead += amount
249
- result .TotalTTLBMS += time .Since (start ).Milliseconds ()
293
+ result .TotalTTLBMS += time .Since (reqStart ).Milliseconds ()
294
+
295
+ result .TotalTestTimeMS += time .Since (testStart ).Milliseconds ()
250
296
251
297
if err != nil {
252
298
ll .Error ("failed to discard response body" , "error" , err )
0 commit comments