Ai
1 Star 0 Fork 0

yonglinux/rpcx-sun-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
root 提交于 2022-02-17 17:49 +08:00 . update
//go run -tags quic client.go
package main
import (
"context"
"crypto/tls"
"crypto/x509"
"flag"
"fmt"
"io/ioutil"
"log"
"time"
"github.com/smallnest/rpcx/client"
)
var (
addr = flag.String("addr", "127.0.0.1:8972", "server address")
)
type Args struct {
A int
B int
}
type Reply struct {
C int
}
func main() {
flag.Parse()
// CA
caCertPEM, err := ioutil.ReadFile("../ca.pem")
if err != nil {
panic(err)
}
roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM(caCertPEM)
if !ok {
panic("failed to parse root certificate")
}
conf := &tls.Config{
// InsecureSkipVerify: true,
RootCAs: roots,
}
option := client.DefaultOption
option.TLSConfig = conf
d, _ := client.NewPeer2PeerDiscovery("quic@"+*addr, "")
xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, option)
defer xclient.Close()
args := &Args{
A: 10,
B: 20,
}
start := time.Now()
for i := 0; i < 100000; i++ {
reply := &Reply{}
err := xclient.Call(context.Background(), "Mul", args, reply)
if err != nil {
log.Fatalf("failed to call: %v", err)
}
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
}
t := time.Since(start).Nanoseconds() / int64(time.Millisecond)
fmt.Printf("tps: %d calls/s\n", 100000*1000/int(t))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yonglinux/rpcx-sun-examples.git
git@gitee.com:yonglinux/rpcx-sun-examples.git
yonglinux
rpcx-sun-examples
rpcx-sun-examples
v1.1.8

搜索帮助