-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbenchmark_test.go
77 lines (64 loc) · 2.05 KB
/
benchmark_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
/*
* @Author: Malin Xie
* @Description:
* @Date: 2021-08-25 19:33:37
*/
// Go support for Protocol Buffers RPC which compatible with https://github.com/Baidu-ecom/Jprotobuf-rpc-socket
//
// Copyright 2002-2007 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* @Author: Malin Xie
* @Description:
* @Date: 2021-08-03 15:52:08
*/
package baidurpc_test
import (
"testing"
"time"
baidurpc "github.com/baidu-golang/pbrpc"
"google.golang.org/protobuf/proto"
)
// BenchmarkTestLocalConnectionPerformance bench mark test
func BenchmarkTestLocalConnectionPerformance(b *testing.B) {
host := "localhost"
port := PORT_1
tcpServer := startRpcServer(0)
defer stopRpcServer(tcpServer)
conn, client, _ := createClient()
defer client.Close()
defer conn.Close()
url := baidurpc.URL{}
url.SetHost(&host).SetPort(&port)
timeout := time.Second * 5
// create client by simple connection
connection, err := baidurpc.NewTCPConnection(url, &timeout)
if err != nil {
return
}
defer connection.Close()
for i := 0; i < b.N; i++ {
doSimpleRPCInvokeWithSignature(client, "EchoService", "echo")
}
}
// doSimpleRPCInvokeWithSignature send rpc request
func doSimpleRPCInvokeWithSignature(rpcClient *baidurpc.RpcClient, serviceName, methodName string) {
rpcInvocation := baidurpc.NewRpcInvocation(&serviceName, &methodName)
name := "马林"
dm := DataMessage{Name: name}
rpcInvocation.SetParameterIn(&dm)
rpcInvocation.LogId = proto.Int64(1)
parameterOut := DataMessage{}
rpcClient.SendRpcRequest(rpcInvocation, ¶meterOut)
}