Skip to content

Commit

Permalink
add GRPC_HIGH_SCALE=true
Browse files Browse the repository at this point in the history
  • Loading branch information
lil5 committed Dec 19, 2024
1 parent 0ecebb2 commit 416b6e0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TB_ADDRESSES=3033
# USE_GRPC=true
# GRPC_HEALTH_SERVER=true
# GRPC_REFLECTION=true
# GRPC_HIGH_SCALE=true

# IS_BUFFERED=true
# BUFFER_SIZE=20
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type config struct {
UseGrpc bool
GrpcHealthServer bool
GrpcReflection bool
GrpcHighScale bool

IsBuffered bool
BufferSize int
Expand Down Expand Up @@ -96,6 +97,7 @@ func NewConfig() (ok bool) {
UseGrpc: useGrpc,
GrpcHealthServer: os.Getenv("GRPC_HEALTH_SERVER") == "true",
GrpcReflection: os.Getenv("GRPC_REFLECTION") == "true",
GrpcHighScale: os.Getenv("GRPC_HIGH_SCALE") == "true",

IsBuffered: isBuffered,
BufferSize: bufferSize,
Expand Down
18 changes: 17 additions & 1 deletion grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log/slog"
"net"
"os"
"time"

"github.com/lil5/tigerbeetle_api/config"
"github.com/lil5/tigerbeetle_api/metrics"
Expand All @@ -13,6 +14,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/health"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/reflection"

grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
Expand All @@ -28,7 +30,21 @@ func NewServer() {
slog.Error("Failed to listen", "error", err)
os.Exit(1)
}
s := grpc.NewServer()

var s *grpc.Server
if config.Config.GrpcHighScale {
s = grpc.NewServer(
grpc.KeepaliveParams(keepalive.ServerParameters{
MaxConnectionAge: 5 * time.Minute,
Time: 60 * time.Second,
Timeout: 20 * time.Second,
}),
grpc.MaxConcurrentStreams(50_000),
)
} else {
s = grpc.NewServer()
}

app := NewApp()
defer app.Close()
proto.RegisterTigerBeetleServer(s, app)
Expand Down

0 comments on commit 416b6e0

Please sign in to comment.