summaryrefslogtreecommitdiffstats
path: root/examples/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cmd')
-rw-r--r--examples/cmd/perf-bench/perf-bench.go58
1 files changed, 14 insertions, 44 deletions
diff --git a/examples/cmd/perf-bench/perf-bench.go b/examples/cmd/perf-bench/perf-bench.go
index b1f4dcf..5b4b17d 100644
--- a/examples/cmd/perf-bench/perf-bench.go
+++ b/examples/cmd/perf-bench/perf-bench.go
@@ -21,7 +21,6 @@ import (
"fmt"
"log"
"os"
- "sync"
"time"
"github.com/pkg/profile"
@@ -30,12 +29,12 @@ import (
"git.fd.io/govpp.git"
"git.fd.io/govpp.git/api"
"git.fd.io/govpp.git/core"
- "git.fd.io/govpp.git/core/bin_api/vpe"
+ "git.fd.io/govpp.git/examples/bin_api/vpe"
)
const (
defaultSyncRequestCount = 1000
- defaultAsyncRequestCount = 1000000
+ defaultAsyncRequestCount = 10000
)
func main() {
@@ -43,7 +42,7 @@ func main() {
var sync, prof bool
var cnt int
flag.BoolVar(&sync, "sync", false, "run synchronous perf test")
- flag.IntVar(&cnt, "cnt", 0, "count of requests to be sent to VPP")
+ flag.IntVar(&cnt, "count", 0, "count of requests to be sent to VPP")
flag.BoolVar(&prof, "prof", false, "generate profile data")
flag.Parse()
@@ -113,50 +112,21 @@ func syncTest(ch api.Channel, cnt int) {
func asyncTest(ch api.Channel, cnt int) {
fmt.Printf("Running asynchronous perf test with %d requests...\n", cnt)
- // start a new go routine that reads the replies
- var wg sync.WaitGroup
- wg.Add(1)
- go readAsyncReplies(ch, cnt, &wg)
+ ctxChan := make(chan api.RequestCtx, cnt)
- // send asynchronous requests
- sendAsyncRequests(ch, cnt)
-
- // wait until all replies are recieved
- wg.Wait()
-}
-
-func sendAsyncRequests(ch api.Channel, cnt int) {
- for i := 0; i < cnt; i++ {
- ch.GetRequestChannel() <- &api.VppRequest{
- Message: &vpe.ControlPing{},
- }
- }
-}
-
-func readAsyncReplies(ch api.Channel, expectedCnt int, wg *sync.WaitGroup) {
- cnt := 0
-
- for {
- // receive a reply
- reply := <-ch.GetReplyChannel()
- if reply.Error != nil {
- log.Println("Error in reply:", reply.Error)
- os.Exit(1)
+ go func() {
+ for i := 0; i < cnt; i++ {
+ ctxChan <- ch.SendRequest(&vpe.ControlPing{})
}
+ close(ctxChan)
+ fmt.Printf("Sending asynchronous requests finished\n")
+ }()
- // decode the message
- msg := &vpe.ControlPingReply{}
- err := ch.GetMessageDecoder().DecodeMsg(reply.Data, msg)
- if reply.Error != nil {
- log.Println("Error by decoding:", err)
+ for ctx := range ctxChan {
+ reply := &vpe.ControlPingReply{}
+ if err := ctx.ReceiveReply(reply); err != nil {
+ log.Println("Error in reply:", err)
os.Exit(1)
}
-
- // count and return if done
- cnt++
- if cnt >= expectedCnt {
- wg.Done()
- return
- }
}
}