forked from Ja7ad/grpc-unix-socket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrpc_test.go
72 lines (58 loc) · 1.28 KB
/
grpc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"
"net"
"os"
"runtime/pprof"
"testing"
"time"
)
func Benchmark_UNIX(b *testing.B) {
f, err := os.Create("unix.prof")
if err != nil {
b.Fatal(err)
}
if err := pprof.StartCPUProfile(f); err != nil {
b.Fatal(err)
}
defer pprof.StopCPUProfile()
dialer := func(addr string, t time.Duration) (net.Conn, error) {
return net.Dial(PROTOCOL, addr)
}
conn, err := grpc.Dial(SOCKET, grpc.WithInsecure(), grpc.WithDialer(dialer))
if err != nil {
b.Fatal(err)
}
health := grpc_health_v1.NewHealthClient(conn)
ctx := context.Background()
for i := 0; i < b.N; i++ {
_, err := health.Check(ctx, &grpc_health_v1.HealthCheckRequest{})
if err != nil {
b.Fatal(err)
}
}
}
func Benchmark_TCP(b *testing.B) {
f, err := os.Create("tcp.prof")
if err != nil {
b.Fatal(err)
}
if err := pprof.StartCPUProfile(f); err != nil {
b.Fatal(err)
}
defer pprof.StopCPUProfile()
conn, err := grpc.Dial(ADDR, grpc.WithInsecure())
if err != nil {
b.Fatal(err)
}
health := grpc_health_v1.NewHealthClient(conn)
ctx := context.Background()
for i := 0; i < b.N; i++ {
_, err := health.Check(ctx, &grpc_health_v1.HealthCheckRequest{})
if err != nil {
b.Fatal(err)
}
}
}