Esempio n. 1
0
func main() {
	flag.Parse()

	grpc.EnableTracing = true

	flag.Parse()
	lis, err := net.Listen("tcp", *port)
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	grpcServer := grpc.NewServer()

	var downstreamClients []pb.PingClient
	for _, d := range strings.Split(*downstreams, ",") {
		if d == "" {
			continue
		}
		log.Println(d)
		conn, err := grpc.Dial(d, grpc.WithBlock())
		if err != nil {
			log.Fatalf("In here " + err.Error())
		}
		defer conn.Close()

		downstreamClients = append(downstreamClients, pb.NewPingClient(conn))
	}
	pb.RegisterPingServer(grpcServer, &pingServer{downstreams: downstreamClients})

	go grpcServer.Serve(lis)

	log.Fatal(http.ListenAndServe(*httpPort, nil))
}
Esempio n. 2
0
func main() {
	grpc.EnableTracing = false

	conn, err := grpc.Dial("localhost:4567", grpc.WithBlock())
	if err != nil {
		os.Exit(1)
	}
	defer conn.Close()

	client := pb.NewPingClient(conn)

	ctx := context.Background()
	t := time.Now()
	req := pb.PingRequest{t.UnixNano()}
	resp, err := client.Ping(ctx, &req)
	if err != nil {
		os.Exit(1)
	}

	t2 := time.Now()

	then := time.Unix(0, resp.TimeBack)

	reqdelay := then.Sub(t)
	log.Println("req ", reqdelay)

	repdelay := t2.Sub(then)
	log.Println("rep ", repdelay)
}
Esempio n. 3
0
func BenchmarkMain(tst *testing.B) {
	conn, err := grpc.Dial("localhost:4567", grpc.WithBlock())
	if err != nil {
		os.Exit(1)
	}
	defer conn.Close()

	client := pb.NewPingClient(conn)

	tst.ResetTimer()
	for n := 0; n < tst.N; n++ {
		ctx := context.Background()
		t := time.Now()
		req := pb.PingRequest{t.UnixNano()}
		_, err := client.Ping(ctx, &req)
		if err != nil {
			tst.FailNow()
		}

		/*
			t2 := time.Now()

			then := time.Unix(0, resp.TimeBack)

			reqdelay := then.Sub(t)
			log.Println("req ", reqdelay)

			repdelay := t2.Sub(then)
			log.Println("rep ", repdelay)
		*/
	}
}