From c4ccfc75f0698e148cfa37a3a1dda1a46bb29109 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Tue, 21 Aug 2018 15:47:30 +0200 Subject: Fix perf-bench example Change-Id: I62a7a27adbb44b9d8070b448c17bb7781b0637fe Signed-off-by: Ondrej Fabry --- examples/cmd/perf-bench/perf-bench.go | 58 +++++++++-------------------------- 1 file changed, 14 insertions(+), 44 deletions(-) (limited to 'examples/cmd') 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 - } } } -- cgit 1.2.3-korg