From 525b83531fdac047b70bcfaa517d124813f586d4 Mon Sep 17 00:00:00 2001 From: justimkiss Date: Mon, 23 Sep 2019 21:10:35 +0800 Subject: [PATCH 1/4] add protocol_conf default value --- go.mod | 2 ++ protocol/dubbo/client.go | 44 +++++++++++++++++----------------- protocol/dubbo/config.go | 51 ++++++++++++++++++++++++++++++++++++++++ protocol/dubbo/server.go | 45 ++++++++++++++++++----------------- 4 files changed, 100 insertions(+), 42 deletions(-) diff --git a/go.mod b/go.mod index 09948c93c5..871c093c0b 100644 --- a/go.mod +++ b/go.mod @@ -50,3 +50,5 @@ require ( google.golang.org/grpc v1.22.1 gopkg.in/yaml.v2 v2.2.2 ) + +go 1.13 diff --git a/protocol/dubbo/client.go b/protocol/dubbo/client.go index 4927f51cf7..03ab704676 100644 --- a/protocol/dubbo/client.go +++ b/protocol/dubbo/client.go @@ -53,33 +53,35 @@ var ( func init() { // load clientconfig from consumer_config - protocolConf := config.GetConsumerConfig().ProtocolConf - if protocolConf == nil { - logger.Warnf("protocol_conf is nil") - return - } - dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO] - if dubboConf == nil { - logger.Warnf("dubboConf is nil") + // default use dubbo + consumerConfig := config.GetConsumerConfig() + if consumerConfig.ApplicationConfig == nil { return } - - dubboConfByte, err := yaml.Marshal(dubboConf) - if err != nil { - panic(err) - } - conf := &ClientConfig{} - err = yaml.Unmarshal(dubboConfByte, conf) - if err != nil { - panic(err) + protocolConf := config.GetConsumerConfig().ProtocolConf + defaultClientConfig := GetDefaultClientConfig() + if protocolConf == nil { + logger.Info("protocol_conf default use dubbo config") + } else { + dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO] + if dubboConf == nil { + logger.Warnf("dubboConf is nil") + return + } + dubboConfByte, err := yaml.Marshal(dubboConf) + if err != nil { + panic(err) + } + err = yaml.Unmarshal(dubboConfByte, &defaultClientConfig) + if err != nil { + panic(err) + } } - - if err := conf.CheckValidity(); err != nil { + clientConf = &defaultClientConfig + if err := clientConf.CheckValidity(); err != nil { logger.Warnf("[CheckValidity] error: %v", err) return } - - clientConf = conf setClientGrpool() } diff --git a/protocol/dubbo/config.go b/protocol/dubbo/config.go index 1ac3c9ad97..893a94e6c8 100644 --- a/protocol/dubbo/config.go +++ b/protocol/dubbo/config.go @@ -90,6 +90,57 @@ type ( } ) +func GetDefaultClientConfig() ClientConfig { + return ClientConfig{ + ReconnectInterval: 0, + ConnectionNum: 16, + HeartbeatPeriod: "5s", + SessionTimeout: "20s", + PoolSize: 64, + PoolTTL: 600, + GrPoolSize: 1200, + QueueLen: 64, + QueueNumber: 60, + GettySessionParam: GettySessionParam{ + CompressEncoding: false, + TcpNoDelay: true, + TcpKeepAlive: true, + KeepAlivePeriod: "120s", + TcpRBufSize: 262144, + TcpWBufSize: 65536, + PkgWQSize: 512, + TcpReadTimeout: "1s", + TcpWriteTimeout: "5s", + WaitTimeout: "1s", + MaxMsgLen: 2014, + SessionName: "client", + }} +} + +func GetDefaultServerConfig() ServerConfig { + return ServerConfig{ + SessionTimeout: "20s", + SessionNumber: 700, + GrPoolSize: 120, + QueueNumber: 6, + QueueLen: 64, + GettySessionParam: GettySessionParam{ + CompressEncoding: false, + TcpNoDelay: true, + TcpKeepAlive: true, + KeepAlivePeriod: "120s", + TcpRBufSize: 262144, + TcpWBufSize: 65536, + PkgWQSize: 512, + TcpReadTimeout: "1s", + TcpWriteTimeout: "5s", + WaitTimeout: "1s", + MaxMsgLen: 1024, + SessionName: "server", + }, + } +} + func (c *GettySessionParam) CheckValidity() error { var err error diff --git a/protocol/dubbo/server.go b/protocol/dubbo/server.go index 5f93a794d2..648c9f8aa8 100644 --- a/protocol/dubbo/server.go +++ b/protocol/dubbo/server.go @@ -42,32 +42,35 @@ var ( func init() { // load clientconfig from provider_config - protocolConf := config.GetProviderConfig().ProtocolConf - if protocolConf == nil { - logger.Warnf("protocol_conf is nil") - return - } - dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO] - if dubboConf == nil { - logger.Warnf("dubboConf is nil") + // default use dubbo + providerConfig := config.GetProviderConfig() + if providerConfig.ApplicationConfig == nil { return } - - dubboConfByte, err := yaml.Marshal(dubboConf) - if err != nil { - panic(err) - } - conf := &ServerConfig{} - err = yaml.Unmarshal(dubboConfByte, conf) - if err != nil { - panic(err) + protocolConf := providerConfig.ProtocolConf + defaultServerConfig := GetDefaultServerConfig() + if protocolConf == nil { + logger.Info("protocol_conf default use dubbo config") + } else { + dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO] + if dubboConf == nil { + logger.Warnf("dubboConf is nil") + return + } + + dubboConfByte, err := yaml.Marshal(dubboConf) + if err != nil { + panic(err) + } + err = yaml.Unmarshal(dubboConfByte, &defaultServerConfig) + if err != nil { + panic(err) + } } - - if err := conf.CheckValidity(); err != nil { + srvConf = &defaultServerConfig + if err := srvConf.CheckValidity(); err != nil { panic(err) } - - srvConf = conf SetServerGrpool() } From a2f593caeab67481b3f4953192c7e51a7cce3e47 Mon Sep 17 00:00:00 2001 From: justimkiss Date: Mon, 23 Sep 2019 21:13:54 +0800 Subject: [PATCH 2/4] add protocol_conf default values --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index 871c093c0b..129397add0 100644 --- a/go.mod +++ b/go.mod @@ -51,4 +51,3 @@ require ( gopkg.in/yaml.v2 v2.2.2 ) -go 1.13 From 92537bd781cf9163b73a0d10b1e3e84058ea4fbf Mon Sep 17 00:00:00 2001 From: justimkiss Date: Mon, 23 Sep 2019 22:11:37 +0800 Subject: [PATCH 3/4] remove blank line --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index 129397add0..09948c93c5 100644 --- a/go.mod +++ b/go.mod @@ -50,4 +50,3 @@ require ( google.golang.org/grpc v1.22.1 gopkg.in/yaml.v2 v2.2.2 ) - From 0ee4975f32db7a80745edfdd366dca13d5f78263 Mon Sep 17 00:00:00 2001 From: justimkiss Date: Fri, 27 Sep 2019 11:47:58 +0800 Subject: [PATCH 4/4] modify default value --- protocol/dubbo/config.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/protocol/dubbo/config.go b/protocol/dubbo/config.go index 893a94e6c8..5371c58747 100644 --- a/protocol/dubbo/config.go +++ b/protocol/dubbo/config.go @@ -98,9 +98,9 @@ func GetDefaultClientConfig() ClientConfig { SessionTimeout: "20s", PoolSize: 64, PoolTTL: 600, - GrPoolSize: 1200, + GrPoolSize: 200, QueueLen: 64, - QueueNumber: 60, + QueueNumber: 10, GettySessionParam: GettySessionParam{ CompressEncoding: false, TcpNoDelay: true, @@ -112,7 +112,7 @@ func GetDefaultClientConfig() ClientConfig { TcpReadTimeout: "1s", TcpWriteTimeout: "5s", WaitTimeout: "1s", - MaxMsgLen: 2014, + MaxMsgLen: 102400, SessionName: "client", }} } @@ -135,7 +135,7 @@ func GetDefaultServerConfig() ServerConfig { TcpReadTimeout: "1s", TcpWriteTimeout: "5s", WaitTimeout: "1s", - MaxMsgLen: 1024, + MaxMsgLen: 102400, SessionName: "server", }, }