From eb455d6e43588c6a2671f4bebd3b3b5ecb45c42b Mon Sep 17 00:00:00 2001 From: Alexey Kostin Date: Mon, 4 Mar 2019 17:42:36 +0300 Subject: [PATCH] Print avg statistics after benchmark. Fix avgspeed counting --- ceph-gobench.go | 42 +++++++++++++++++++++++++++++++++++++----- types.go | 5 +++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/ceph-gobench.go b/ceph-gobench.go index 580a94e..38515e1 100644 --- a/ceph-gobench.go +++ b/ceph-gobench.go @@ -17,7 +17,7 @@ import ( ) func bench(cephconn *cephconnection, osddevice Device, buff *[]byte, startbuff *[]byte, params *params, - wg *sync.WaitGroup, result chan string) { + wg *sync.WaitGroup, result chan string, totalLats chan avgLatencies) { defer wg.Done() threadresult := make(chan []time.Duration, params.threadsCount) var objectnames []string @@ -121,11 +121,13 @@ func bench(cephconn *cephconnection, osddevice Device, buff *[]byte, startbuff * } buffer.WriteString("\n\n") + totalLats <- avgLatencies{latencytotal: latencytotal, len: int64(len(osdlatencies))} + latencytotal = latencytotal / int64(len(osdlatencies)) // iops = 1s / latency iops := 1000000 / latencytotal * int64(params.threadsCount) // avg speed = iops * block size / 1 MB - avgspeed := 1000000 / float64(latencytotal) * float64(params.blocksize) / 1024 / 1024 * float64(params.threadsCount) + avgspeed := float64(iops) * float64(params.blocksize) / 1024 / 1024 avgline := fmt.Sprintf("Avg iops: %-5v Avg speed: %.3f MB/s Total writes count: %-5v Total writes (MB): %-5v\n\n", iops, avgspeed, len(osdlatencies), uint64(len(osdlatencies))*params.blocksize/1024/1024) switch { @@ -235,12 +237,16 @@ func main() { var wg sync.WaitGroup results := make(chan string, len(osddevices)*int(params.threadsCount)) + totalLats := make(chan avgLatencies, len(osddevices)) + avgLats := []avgLatencies{} + log.Println("Benchmark started") for _, osd := range osddevices { wg.Add(1) if params.parallel == true { - go bench(cephconn, osd, &buff, &startbuff, ¶ms, &wg, results) + go bench(cephconn, osd, &buff, &startbuff, ¶ms, &wg, results, totalLats) } else { - bench(cephconn, osd, &buff, &startbuff, ¶ms, &wg, results) + bench(cephconn, osd, &buff, &startbuff, ¶ms, &wg, results, totalLats) + avgLats = append(avgLats, <-totalLats) log.Println(<-results) } @@ -250,12 +256,38 @@ func main() { go func() { wg.Wait() close(results) + close(totalLats) }() for message := range results { log.Println(message) - + } + for lat := range totalLats { + avgLats = append(avgLats, lat) } } + sumLat := int64(0) + countLat := int64(0) + for _, avgLat := range avgLats { + sumLat += avgLat.latencytotal + countLat += avgLat.len + } + + //count avg statistics + sumLat = sumLat / int64(countLat) + avgIops := 1000000 / sumLat * int64(params.threadsCount) + sumIops := 1000000 / sumLat * int64(params.threadsCount) * int64(len(osddevices)) + avgSpeed := float64(avgIops) * float64(params.blocksize) / 1024 / 1024 + sumSpeed := float64(sumIops) * float64(params.blocksize) / 1024 / 1024 + + color.Set(color.FgHiYellow) + defer color.Unset() + + fmt.Printf("Summary avg iops per osd:%5d Summary avg speed per osd: %.3f MB/s\n"+ + "Total writes count:%11d Total writes (MB): %v\n", + avgIops, avgSpeed, countLat, uint64(countLat)*params.blocksize/1024/1024) + if params.parallel { + fmt.Printf("Summary avg iops:%13d Summary avg speed: %.3f MB/s\n", sumIops, sumSpeed) + } } diff --git a/types.go b/types.go index 7fac2e1..2ab04fa 100644 --- a/types.go +++ b/types.go @@ -386,3 +386,8 @@ type OsdMap struct { Up []uint64 `json:"up"` UpPrimary int64 `json:"up_primary"` } + +type avgLatencies struct { + latencytotal int64 + len int64 +}