1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-11 10:18:08 +09:00

drpc experiment

This commit is contained in:
Sergey Cherepanov 2022-07-14 16:59:01 +03:00 committed by Mikhail Iudin
parent cff04397d1
commit 15af9eec36
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
9 changed files with 314 additions and 4 deletions

View file

@ -9,6 +9,9 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"log"
"net"
"storj.io/drpc"
"storj.io/drpc/drpcconn"
"time"
)
@ -21,7 +24,11 @@ func main() {
if err != nil {
panic(err)
}
benchGrpc(conf)
benchDrpc(conf)
}
func benchGrpc(conf *config.Config) {
var opts []grpc.DialOption
if conf.GrpcServer.TLS {
creds, err := credentials.NewClientTLSFromFile(conf.GrpcServer.TLSCertFile, "127.0.0.1")
@ -39,12 +46,15 @@ func main() {
}
defer conn.Close()
client := syncproto.NewAnytypeSyncClient(conn)
stream, err := client.Ping(context.TODO())
if err != nil {
panic(err)
}
st := time.Now()
n := 1000000
n := 100000
for i := 0; i < n; i++ {
if err = stream.Send(&syncproto.PingRequest{
Seq: int64(i),
@ -58,5 +68,52 @@ func main() {
}
dur := time.Since(st)
fmt.Printf("%d req for %v (%d per sec)\n", n, dur, int(float64(n)/dur.Seconds()))
}
func benchDrpc(conf *config.Config) {
rawconn, err := net.Dial("tcp", conf.GrpcServer.ListenAddrs[1])
if err != nil {
panic(err)
}
conn := drpcconn.New(rawconn)
defer conn.Close()
client := syncproto.NewDRPCAnytypeSyncClient(conn)
stream, err := client.Ping(context.TODO())
if err != nil {
panic(err)
}
st := time.Now()
n := 100000
for i := 0; i < n; i++ {
if err = stream.MsgSend(&syncproto.PingRequest{
Seq: int64(i),
}, enc{}); err != nil {
panic(err)
}
msg := &syncproto.PingResponse{}
err := stream.MsgRecv(msg, enc{})
if err != nil {
panic(err)
}
}
dur := time.Since(st)
fmt.Printf("%d req for %v (%d per sec)\n", n, dur, int(float64(n)/dur.Seconds()))
}
type enc struct {
}
func (e enc) Marshal(msg drpc.Message) ([]byte, error) {
return msg.(interface {
Marshal() ([]byte, error)
}).Marshal()
}
func (e enc) Unmarshal(buf []byte, msg drpc.Message) error {
return msg.(interface {
Unmarshal(buf []byte) error
}).Unmarshal(buf)
}

View file

@ -81,4 +81,5 @@ func main() {
func Bootstrap(a *app.App) {
a.Register(server.New())
a.Register(server.NewDRPC())
}