grpc server and test client implementation

This commit is contained in:
Sergey Cherepanov authored and Mikhail Iudin committed 2022-07-14 00:22:28 +03:00
1 parent 55d07ca757
commit cff04397d1
14 files changed
+2342 -27

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
package main
import (
"context"
"fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/syncproto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"log"
"time"
)
// req/rep 1000000 req for 1m56.663998462s (8571 per sec)
// stream 1000000 req for 1m25.54958362s (11689 per sec)
func main() {
conf, err := config.NewFromFile("etc/config.yml")
if err != nil {
panic(err)
}
var opts []grpc.DialOption
if conf.GrpcServer.TLS {
creds, err := credentials.NewClientTLSFromFile(conf.GrpcServer.TLSCertFile, "127.0.0.1")
if err != nil {
log.Fatalf("Failed to create TLS credentials %v", err)
}
opts = append(opts, grpc.WithTransportCredentials(creds))
} else {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
conn, err := grpc.Dial(conf.GrpcServer.ListenAddrs[0], opts...)
if err != nil {
log.Fatalf("fail to dial: %v", err)
}
defer conn.Close()
client := syncproto.NewAnytypeSyncClient(conn)
stream, err := client.Ping(context.TODO())
if err != nil {
panic(err)
}
st := time.Now()
n := 1000000
for i := 0; i < n; i++ {
if err = stream.Send(&syncproto.PingRequest{
Seq: int64(i),
}); err != nil {
panic(err)
}
_, err := stream.Recv()
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()))
}
+14 -16
View File
@@ -7,9 +7,10 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/treecache"
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/server"
"go.uber.org/zap"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
@@ -19,10 +20,9 @@ import (
var log = logger.NewNamed("main")
var (
flagConfigFile = flag.String("c", "etc/config.yml", "path to config file")
flagAccountFile = flag.String("a", "etc/account.yaml", "path to account file")
flagVersion = flag.Bool("v", false, "show version and exit")
flagHelp = flag.Bool("h", false, "show help and exit")
flagConfigFile = flag.String("c", "etc/config.yml", "path to config file")
flagVersion = flag.Bool("v", false, "show version and exit")
flagHelp = flag.Bool("h", false, "show help and exit")
)
func main() {
@@ -37,6 +37,12 @@ func main() {
return
}
if debug, ok := os.LookupEnv("ANYPROF"); ok && debug != "" {
go func() {
http.ListenAndServe(debug, nil)
}()
}
// create app
ctx := context.Background()
a := new(app.App)
@@ -47,21 +53,13 @@ func main() {
log.Fatal("can't open config file", zap.Error(err))
}
// open account file with node's keys
acc, err := account.NewFromFile(*flagAccountFile)
if err != nil {
log.Fatal("can't open account file", zap.Error(err))
}
// bootstrap components
a.Register(conf)
a.Register(acc)
a.Register(treecache.NewTreeCache())
Bootstrap(a)
// start app
if err := a.Start(ctx); err != nil {
log.Error("can't start app", zap.Error(err))
log.Fatal("can't start app", zap.Error(err))
}
log.Info("app started", zap.String("version", a.Version()))
@@ -82,5 +80,5 @@ func main() {
}
func Bootstrap(a *app.App) {
//a.Register(mycomponent.New())
a.Register(server.New())
}