Skip to content

Commit 2e10f73

Browse files
committed
Added read scale test
1 parent 2235311 commit 2e10f73

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

cmd/main/runtests.go

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"time"
1515
)
1616

17-
const NumScaleThreads = 20
17+
const NumScaleThreads = 40
1818
const UploadSize = 1024*1024*5
1919
const UploadTarget = 1024*1024*1024*5
2020

@@ -204,6 +204,13 @@ func runScale(server, rootPath string) error {
204204
data := make([]byte, UploadSize)
205205
_, _ = rand.Read(data)
206206

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) {
207214
// Now run the scale test - upload files in multiple threads until we
208215
// reach the desired number of uploads
209216
infoMtx := sync.Mutex{}
@@ -213,13 +220,13 @@ func runScale(server, rootPath string) error {
213220

214221
var count int32
215222
wait := sync.WaitGroup{}
216-
println("Running the test threads")
223+
println("Running the upload test. Threads =", NumScaleThreads)
217224
for _, c := range nfsClients {
218225
wait.Add(1)
219226
go func(c nfs4.NfsInterface) {
220227
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))
223230
n, err := c.ReWriteFile(nm, bytes.NewReader(data))
224231
if err != nil {
225232
println("Error: ", err.Error())
@@ -232,7 +239,7 @@ func runScale(server, rootPath string) error {
232239
if !doneUploading {
233240
doneUploading = true
234241
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
236243
println("Uploaded bytes: ", curUploaded, ", time(ms): ", ms,
237244
" rate (MB/s): ", int64(rate))
238245
}
@@ -242,8 +249,56 @@ func runScale(server, rootPath string) error {
242249
}(c)
243250
}
244251
wait.Wait()
252+
}
245253

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()
247302
}
248303

249304
func main() {

0 commit comments

Comments
 (0)