Skip to content

Commit 98709a5

Browse files
fatboy1513caojiawen
andauthored
feat: grpc buffersize from env (#194)
Co-authored-by: caojiawen <[email protected]>
1 parent bc32397 commit 98709a5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

rpc/grpc/grpc_conn_manager.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ package grpc
1616

1717
import (
1818
"errors"
19+
"os"
20+
"strconv"
1921
"sync"
2022
"sync/atomic"
2123
"unsafe"
@@ -45,7 +47,7 @@ func NewGrpcConnectManager(consulUrl string) *GrpcConnectManager {
4547
return g
4648
}
4749

48-
//param是指url的参数,例如:wait=10s&tag=mop,代表这个连接超时10秒建立
50+
// param是指url的参数,例如:wait=10s&tag=mop,代表这个连接超时10秒建立
4951
func (g *GrpcConnectManager) GetConnWithConsul(server, param string) (*grpc.ClientConn, error) {
5052
if connItem, ok := g.GrpcConnectItemMap[server]; ok { //first check
5153
if atomic.LoadPointer(&connItem.ClientConn) != nil {
@@ -133,12 +135,19 @@ func (g *GrpcConnectManager) checkState(conn *grpc.ClientConn) error {
133135
}
134136

135137
func (g *GrpcConnectManager) newGrpcConn(target string) (*grpc.ClientConn, error) {
138+
size := 0
139+
if buffsize, ok := os.LookupEnv("RPC_RBUF"); ok {
140+
size, _ = strconv.Atoi(buffsize)
141+
}
142+
if size < 4096 {
143+
size = 64 * 1024 * 1024
144+
}
136145
conn, err := grpc.Dial(
137146
target,
138147
//grpc.WithBlock(),
139148
grpc.WithInsecure(),
140149
grpc.WithBalancerName("round_robin"),
141-
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(64*1024*1024)),
150+
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(size)),
142151
//grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy": "round_robin"}`),
143152
)
144153
if err != nil {

0 commit comments

Comments
 (0)