X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=examples%2Fperf-bench%2Fperf-bench.go;h=6e25185425c65614098326e6072a03803430e29f;hb=67cea0df30f7ef348e265c9326f7a9f15ba26240;hp=81d183cab23b8554be4831efc9db8f30c1fb18d0;hpb=280b1c6c83b676ef4e592f4ecf60cb5b54b6a753;p=govpp.git diff --git a/examples/perf-bench/perf-bench.go b/examples/perf-bench/perf-bench.go index 81d183c..6e25185 100644 --- a/examples/perf-bench/perf-bench.go +++ b/examples/perf-bench/perf-bench.go @@ -17,6 +17,7 @@ package main import ( + "context" "flag" "fmt" "log" @@ -26,11 +27,11 @@ import ( "github.com/pkg/profile" "github.com/sirupsen/logrus" - "git.fd.io/govpp.git/adapter/socketclient" - "git.fd.io/govpp.git/adapter/statsclient" - "git.fd.io/govpp.git/api" - "git.fd.io/govpp.git/core" - "git.fd.io/govpp.git/examples/binapi/vpe" + "go.fd.io/govpp/adapter/socketclient" + "go.fd.io/govpp/adapter/statsclient" + "go.fd.io/govpp/api" + "go.fd.io/govpp/binapi/memclnt" + "go.fd.io/govpp/core" ) const ( @@ -98,9 +99,11 @@ func main() { if sync { // run synchronous test syncTest(ch, cnt) + //syncTest2(conn, cnt) } else { // run asynchronous test asyncTest(ch, cnt) + //asyncTest2(conn, cnt) } elapsed := time.Since(start) @@ -114,8 +117,8 @@ func syncTest(ch api.Channel, cnt int) { fmt.Printf("Running synchronous perf test with %d requests...\n", cnt) for i := 0; i < cnt; i++ { - req := &vpe.ControlPing{} - reply := &vpe.ControlPingReply{} + req := &memclnt.ControlPing{} + reply := &memclnt.ControlPingReply{} if err := ch.SendRequest(req).ReceiveReply(reply); err != nil { log.Fatalln("Error in reply:", err) @@ -123,6 +126,27 @@ func syncTest(ch api.Channel, cnt int) { } } +func syncTest2(conn api.Connection, cnt int) { + fmt.Printf("Running synchronous perf test with %d requests...\n", cnt) + + stream, err := conn.NewStream(context.Background()) + if err != nil { + log.Fatalln("Error NewStream:", err) + } + for i := 0; i < cnt; i++ { + if err := stream.SendMsg(&memclnt.ControlPing{}); err != nil { + log.Fatalln("Error SendMsg:", err) + } + if msg, err := stream.RecvMsg(); err != nil { + log.Fatalln("Error RecvMsg:", err) + } else if _, ok := msg.(*memclnt.ControlPingReply); ok { + // ok + } else { + log.Fatalf("unexpected reply: %v", msg.GetMessageName()) + } + } +} + func asyncTest(ch api.Channel, cnt int) { fmt.Printf("Running asynchronous perf test with %d requests...\n", cnt) @@ -130,16 +154,48 @@ func asyncTest(ch api.Channel, cnt int) { go func() { for i := 0; i < cnt; i++ { - ctxChan <- ch.SendRequest(&vpe.ControlPing{}) + ctxChan <- ch.SendRequest(&memclnt.ControlPing{}) } close(ctxChan) fmt.Printf("Sending asynchronous requests finished\n") }() for ctx := range ctxChan { - reply := &vpe.ControlPingReply{} + reply := &memclnt.ControlPingReply{} if err := ctx.ReceiveReply(reply); err != nil { log.Fatalln("Error in reply:", err) } } } + +func asyncTest2(conn api.Connection, cnt int) { + fmt.Printf("Running asynchronous perf test with %d requests...\n", cnt) + + ctxChan := make(chan api.Stream, cnt) + + go func() { + for i := 0; i < cnt; i++ { + stream, err := conn.NewStream(context.Background()) + if err != nil { + log.Fatalln("Error NewStream:", err) + } + if err := stream.SendMsg(&memclnt.ControlPing{}); err != nil { + log.Fatalln("Error SendMsg:", err) + } + ctxChan <- stream + } + close(ctxChan) + fmt.Printf("Sending asynchronous requests finished\n") + }() + + for ctx := range ctxChan { + if msg, err := ctx.RecvMsg(); err != nil { + log.Fatalln("Error RecvMsg:", err) + } else if _, ok := msg.(*memclnt.ControlPingReply); ok { + // ok + } else { + log.Fatalf("unexpected reply: %v", msg.GetMessageName()) + } + ctx.Close() + } +}