Skip to content
Permalink
Browse files

Merge pull request #18 from WeiranFang/echo-client

Add go echo client for e2e test
  • Loading branch information...
WeiranFang committed Oct 8, 2019
2 parents 0135f2b + 655f5f8 commit 174e70ce65010087b5d7fc261535c0fa1d021203
@@ -0,0 +1,35 @@
# Echo Client for e2e test

Simple echo client for e2e testing against the echo service defined in
[echo.proto](echo/echo.proto).

## Usage

The client sends out `numRpcs` number of Ping-Pong unary requests sequentially
with request size specified by `reqSize` in KB, and response size specified by
`rspSize` in KB, test result will be printed in console.

## Generate protobuf code

If we need to regenerate pb code for echo grpc service, run:

```sh
./echo/codegen.sh
```

## Run client

Example command for endpoint `some.test.service` with 100 RPCs and 100KB
response size:

```sh
go run echo-client/main.go -numRpcs=100 -rspSize=100
```

Example test result

```sh
[Number of RPCs: 100, Request size: 1KB, Response size: 100KB]
Avg Min p50 p90 p99 Max
Time(ms) 76 74 76 78 109 109
```
@@ -0,0 +1,81 @@
package main

import (
"context"
"flag"
"log"
"sort"
"strings"
"time"

pb "github.com/GoogleCloudPlatform/grpc-gcp-go/e2e-examples/echo/echo"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)

var (
addr = flag.String("addr", "staging-grpc-cfe-benchmarks.googleapis.com:443", "server address")
numRpcs = flag.Int("numRpcs", 1, "number of blocking unary calls")
warmup = flag.Int("warmup", 5, "number of warmup calls before test")
rspSize = flag.Int("rspSize", 1, "response size in KB")
reqSize = flag.Int("reqSize", 1, "request size in KB")
)

func printRsts(numRpcs int, rspSize int, reqSize int, rsts []int) {
sort.Ints(rsts)
n := len(rsts)
sum := 0
for _, r := range rsts {
sum += r
}
log.Printf(
"\n[Number of RPCs: %v, Request size: %vKB, Response size: %vKB]\n"+
"\t\tAvg\tMin\tp50\tp90\tp99\tMax\n"+
"Time(ms)\t%v\t%v\t%v\t%v\t%v\t%v\n",
numRpcs, reqSize, rspSize,
sum/n,
rsts[0],
rsts[int(float64(n)*0.5)],
rsts[int(float64(n)*0.9)],
rsts[int(float64(n)*0.99)],
rsts[n-1],
)
}

func main() {
flag.Parse()
conn, err := grpc.Dial(
*addr,
grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")),
grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()

client := pb.NewGrpcCloudapiClient(conn)
msg := strings.Repeat("x", *reqSize*1024)
req := &pb.EchoWithResponseSizeRequest{EchoMsg: msg, ResponseSize: int32(*rspSize * 1024)}

// begin warmup calls
for i := 0; i < *warmup; i++ {
_, err := client.EchoWithResponseSize(context.Background(), req)
if err != nil {
log.Fatalf("EchoWithResponseSize failed with error during warmup: %v", err)
}
}

rsts := []int{}

// begin tests
for i := 0; i < *numRpcs; i++ {
start := time.Now()
_, err := client.EchoWithResponseSize(context.Background(), req)
if err != nil {
log.Fatalf("EchoWithResponseSize failed with error: %v", err)
}
rsts = append(rsts, int(time.Since(start).Milliseconds()))
}
printRsts(*numRpcs, *rspSize, *reqSize, rsts)

}
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
cd "$(dirname "$0")"

#protoc --plugin=$GOPATH/bin/protoc-gen-go --proto_path=./ --go_out=./ ./echo.proto

protoc --go_out=plugins=grpc:. *.proto

0 comments on commit 174e70c

Please sign in to comment.
You can’t perform that action at this time.