This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_test.go
110 lines (100 loc) · 2.06 KB
/
bench_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"context"
"testing"
"rpcBench/args"
gorpc2 "rpcBench/gorpc"
"rpcBench/mango"
"rpcBench/rpcx"
"rpcBench/standard"
"github.com/smallnest/rpcx/log"
"github.com/valyala/gorpc"
)
const (
sPort = 8569
gPort = 8570
xPort = 8571
mPort = 8572
)
func init() {
log.SetDummyLogger()
gorpc2.RegisterTypes()
go standard.ListenAndServe(sPort)
go gorpc2.ListenAndServe(gPort)
go rpcx.ListenAndServe(xPort)
go mango.ListenAndServe(mPort)
}
func BenchmarkStandard(b *testing.B) {
c := standard.CreateNewClient("localhost", sPort)
b.ResetTimer()
for i := 0; i < b.N; i++ {
var reply int
if err := c.Call(args.MyServerSum, args.Args{A: 10, B: 1}, &reply); err != nil {
b.Error(err)
}
}
b.StopTimer()
c.Close()
}
func BenchmarkGoRPC(b *testing.B) {
c, dc := gorpc2.NewClient("localhost", gPort)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := dc.Call("Sum", &args.Args{A: 10, B: 1})
if err != nil {
b.Error(err)
}
}
b.StopTimer()
c.Stop()
}
func BenchmarkGoRPCBatch(b *testing.B) {
c, dc := gorpc2.NewClient("localhost", gPort)
bc := dc.NewBatch()
b.ResetTimer()
var results []*gorpc.BatchResult
for i := 0; i < b.N; i++ {
results = append(results, bc.Add("Sum", &args.Args{A: 10, B: 1}))
if i%10 == 0 {
bc.Call()
for _, r := range results {
<-r.Done
if r.Error != nil {
b.Error(r.Error)
}
}
results = nil
}
}
if b.N%10 != 0 {
bc.Call()
}
b.StopTimer()
c.Stop()
}
func BenchmarkRPCX(b *testing.B) {
c := rpcx.NewClient("localhost", xPort)
b.ResetTimer()
for i := 0; i < b.N; i++ {
var reply int
if err := c.Call(context.Background(), "Sum", args.Args{A: 10, B: 1}, &reply); err != nil {
b.Error(err)
}
}
b.StopTimer()
c.Close()
}
func BenchmarkNanoMsg(b *testing.B) {
c := mango.NewClient("localhost", mPort)
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := c.Send([]byte("DATE")); err != nil {
b.Errorf("can't send message on push socket: %s", err)
}
if _, err := c.Recv(); err != nil {
b.Errorf("can't receive date: %s", err)
}
}
b.StopTimer()
c.Close()
}