@@ -14,7 +14,7 @@ import (
14
14
"time"
15
15
)
16
16
17
- const NumScaleThreads = 20
17
+ const NumScaleThreads = 40
18
18
const UploadSize = 1024 * 1024 * 5
19
19
const UploadTarget = 1024 * 1024 * 1024 * 5
20
20
@@ -204,6 +204,13 @@ func runScale(server, rootPath string) error {
204
204
data := make ([]byte , UploadSize )
205
205
_ , _ = rand .Read (data )
206
206
207
+ testWriteScaling (nfsClients , rootPath , data )
208
+ testReadScaling (nfsClients , rootPath , data )
209
+
210
+ return nil
211
+ }
212
+
213
+ func testWriteScaling (nfsClients []nfs4.NfsInterface , rootPath string , data []byte ) {
207
214
// Now run the scale test - upload files in multiple threads until we
208
215
// reach the desired number of uploads
209
216
infoMtx := sync.Mutex {}
@@ -213,13 +220,13 @@ func runScale(server, rootPath string) error {
213
220
214
221
var count int32
215
222
wait := sync.WaitGroup {}
216
- println ("Running the test threads" )
223
+ println ("Running the upload test. Threads =" , NumScaleThreads )
217
224
for _ , c := range nfsClients {
218
225
wait .Add (1 )
219
226
go func (c nfs4.NfsInterface ) {
220
227
defer wait .Done ()
221
- for ;! doneUploading ; {
222
- nm := fmt .Sprintf (rootPath + "scale/test-%d" , atomic .AddInt32 (& count , 1 ))
228
+ for ; ! doneUploading ; {
229
+ nm := fmt .Sprintf (rootPath + "scale/test-%d" , atomic .AddInt32 (& count , 1 ))
223
230
n , err := c .ReWriteFile (nm , bytes .NewReader (data ))
224
231
if err != nil {
225
232
println ("Error: " , err .Error ())
@@ -232,7 +239,7 @@ func runScale(server, rootPath string) error {
232
239
if ! doneUploading {
233
240
doneUploading = true
234
241
ms := time .Now ().Sub (start ).Milliseconds ()
235
- rate := (float64 (curUploaded )* 1000.0 / float64 (ms ))/ 1024 / 1024
242
+ rate := (float64 (curUploaded ) * 1000.0 / float64 (ms )) / 1024 / 1024
236
243
println ("Uploaded bytes: " , curUploaded , ", time(ms): " , ms ,
237
244
" rate (MB/s): " , int64 (rate ))
238
245
}
@@ -242,8 +249,56 @@ func runScale(server, rootPath string) error {
242
249
}(c )
243
250
}
244
251
wait .Wait ()
252
+ }
245
253
246
- return nil
254
+ func testReadScaling (nfsClients []nfs4.NfsInterface , rootPath string , data []byte ) {
255
+ // Now run the scale test - upload files in multiple threads until we
256
+ // reach the desired number of uploads
257
+ infoMtx := sync.Mutex {}
258
+ downloadedBytes := uint64 (0 )
259
+ done := false
260
+ start := time .Now ()
261
+
262
+ var count int32
263
+ wait := sync.WaitGroup {}
264
+ println ("Running the read test. Threads =" , NumScaleThreads )
265
+ for _ , c := range nfsClients {
266
+ wait .Add (1 )
267
+ go func (c nfs4.NfsInterface ) {
268
+ defer wait .Done ()
269
+ for ; ! done ; {
270
+ nm := fmt .Sprintf (rootPath + "scale/test-%d" , atomic .AddInt32 (& count , 1 ))
271
+ reader := bytes .NewBufferString ("" )
272
+ n , err := c .ReadFileAll (nm , reader )
273
+ if err != nil {
274
+ println ("Error: " , err .Error ())
275
+ done = true
276
+ }
277
+ resBytes := reader .Bytes ()
278
+ for i := 0 ; i < len (data ); i ++ {
279
+ if data [i ] != resBytes [i ] {
280
+ println ("Data mismatch" )
281
+ done = true
282
+ break
283
+ }
284
+ }
285
+
286
+ curDownloaded := atomic .AddUint64 (& downloadedBytes , n )
287
+ if curDownloaded > UploadTarget {
288
+ infoMtx .Lock ()
289
+ if ! done {
290
+ done = true
291
+ ms := time .Now ().Sub (start ).Milliseconds ()
292
+ rate := (float64 (curDownloaded ) * 1000.0 / float64 (ms )) / 1024 / 1024
293
+ println ("Downloaded bytes: " , curDownloaded , ", time(ms): " , ms ,
294
+ " rate (MB/s): " , int64 (rate ))
295
+ }
296
+ infoMtx .Unlock ()
297
+ }
298
+ }
299
+ }(c )
300
+ }
301
+ wait .Wait ()
247
302
}
248
303
249
304
func main () {
0 commit comments