Here is our test code:

*helloworld.proto*

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}


*main_server.go*

package main

import (
"flag"
"log"
"net"
"runtime"
"sync/atomic"
"time"

pb "benchtest_V1/GRPC/helloworld/helloworld"

"golang.org/x/net/context"
"google.golang.org/grpc"
)

var totalnum int64
type server struct{}
var addr = flag.String("ip", "localhost:50052", "addr")

const (
defaultName = 
"rep:1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
)

// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) 
(*pb.HelloReply, error) {
return &pb.HelloReply{Message: defaultName}, nil
}

func main() {
flag.Parse()
lis, err := net.Listen("tcp", *addr)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
pb.RegisterGreeterServer(s, &server{})
s.Serve(lis)
}

*main_client.go*

package main

import (
"log"
"os"
"os/signal"
"time"
"golang.org/x/net/context"
"flag"
"runtime"
pb "benchtest_V1/GRPC/helloworld/helloworld"
"google.golang.org/grpc"
)

const (
defaultName = 
"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
)

var costtime, sum int64
var count = flag.Int("c", 100, "count")
var linknum = flag.Int("l", 1, "linknum")
var addr = flag.String("ip", "localhost:50052", "addr")

func LoopCallMethod(si chan int64) {
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithInsecure())
defer conn.Close()
if err != nil {
log.Fatalf("did not connect: %v", err)
}

c := pb.NewGreeterClient(conn)
req := &pb.HelloRequest{Name: defaultName}

// warm up
for j := 0; j < 100; j++ {
_, err := c.SayHello(context.Background(), req)
if err != nil {
log.Fatalf("could not greet: %v", err)
}
}

var costtime int64
callnum := 0

for i := 0; i < *count; i++ {
begin := time.Now()
_, err := c.SayHello(context.Background(), req)
if err != nil {
log.Fatalf("could not greet: %v", err)
}
costtime += time.Since(begin).Nanoseconds()
callnum++
//output one time for every 100 invokes
if callnum == 100 {
si <- costtime
costtime = 0
callnum = 0
}
}
}

func main() {
runtime.GOMAXPROCS(0)
flag.Parse()
go fun_print()

exit := make(chan os.Signal)
signal.Notify(exit, os.Kill, os.Interrupt)

chanbuffer := make(chan int64, 10000)
ch := make(chan int)

//invoke
for i := 0; i < *linknum; i++ {
go LoopCallMethod(chanbuffer)
}

//stats groutine
go func() {
for {
select {
case <-exit:
ch <- 1
case cb := <-chanbuffer:
costtime += cb
sum += 100
}
}
}()

<-ch
}

// output info each min
func fun_print() {
for {
select {
case <-time.Tick(1000 * time.Millisecond):
if sum == 0 {
sum = 1
}
log.Printf("Call succ num: %d, Delay=%v, NumGoroutine=%v\n",
sum,
costtime/(sum*int64(time.Microsecond)),
runtime.NumGoroutine())
sum, costtime = 0, 0
}
}
}


Junjie

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/daa2c903-c79d-4957-aa2d-66a05dbfd12a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to