liliang 7 hónapja
szülő
commit
246a52dbf7

+ 23 - 23
components/mongo/component.go

@@ -59,13 +59,17 @@ func (s *Component) Init() {
 			item := dbGroup.GetConfig(i)
 
 			var (
-				enable    = item.GetBool("enable", true)
-				id        = item.GetString("db_id")
-				dbName    = item.GetString("db_name")
-				uri       = item.GetString("uri")
-				timeout   = time.Duration(item.GetInt64("timeout", 3)) * time.Second
-				tlsEnable = item.GetInt("tls")
-				maxClient = item.GetInt("maxClient")
+				enable          = item.GetBool("enable", true)
+				id              = item.GetString("db_id")
+				dbName          = item.GetString("db_name")
+				uri             = item.GetString("uri")
+				timeout         = time.Duration(item.GetInt64("timeout", 3)) * time.Second
+				tlsEnable       = item.GetInt("tls")
+				maxPoolSize     = item.GetInt("maxPoolSize")
+				minPoolSize     = item.GetInt("minPoolSize")
+				maxConnIdleTime = item.GetInt("maxConnIdleTime")
+				connectTimeout  = item.GetInt("connectTimeout")
+				socketTimeout   = item.GetInt("socketTimeout")
 			)
 
 			for _, key := range mongoIdList.Keys() {
@@ -78,7 +82,7 @@ func (s *Component) Init() {
 					panic(fmt.Sprintf("[dbName = %s] is disabled!", dbName))
 				}
 
-				db, err := CreateDatabase(uri, dbName, tlsEnable, uint64(maxClient), timeout)
+				db, err := CreateDatabase(uri, dbName, tlsEnable, uint64(maxPoolSize), uint64(minPoolSize), maxConnIdleTime, connectTimeout, socketTimeout, timeout)
 				if err != nil {
 					panic(fmt.Sprintf("[dbName = %s] create mongodb fail. error = %s", dbName, err))
 				}
@@ -90,7 +94,7 @@ func (s *Component) Init() {
 	}
 }
 
-func CreateDatabase(uri, dbName string, tlsEnable int, maxClient uint64, timeout ...time.Duration) (*mongo.Database, error) {
+func CreateDatabase(uri, dbName string, tlsEnable int, maxPoolSize uint64, minPoolSize uint64, maxConnIdleTime int, connectTimeout, socketTimeout int, timeout ...time.Duration) (*mongo.Database, error) {
 	tt := 5 * time.Second
 
 	if len(timeout) > 0 && timeout[0].Seconds() > 3 {
@@ -104,23 +108,19 @@ func CreateDatabase(uri, dbName string, tlsEnable int, maxClient uint64, timeout
 			PreferServerCipherSuites: true,
 		}
 
-		o = options.Client().ApplyURI(uri).SetMaxPoolSize(500). //最大连接
-			SetMinPoolSize(20).                  //最小连接
-			SetMaxConnIdleTime(3 * time.Minute). //连接空闲时间
-			SetMaxConnIdleTime(5 * time.Minute). //连接生命周期
-			SetConnectTimeout(10 * time.Second). //连接超时时间
-			SetSocketTimeout(10 * time.Second).SetTLSConfig(tlsConfig)   //套接字超时时间
+		o = options.Client().ApplyURI(uri).SetMaxPoolSize(maxPoolSize). //最大连接
+										SetMinPoolSize(minPoolSize).                                                         //最小连接
+										SetMaxConnIdleTime(time.Duration(maxConnIdleTime) * time.Second).                    //连接空闲时间
+										SetConnectTimeout(time.Duration(connectTimeout) * time.Second).                      //连接超时时间
+										SetSocketTimeout(time.Duration(socketTimeout) * time.Second).SetTLSConfig(tlsConfig) //套接字超时时间
 	} else {
-		o = options.Client().ApplyURI(uri).SetMaxPoolSize(500). //最大连接
-			SetMinPoolSize(20).                  //最小连接
-			SetMaxConnIdleTime(3 * time.Minute). //连接空闲时间
-			SetMaxConnIdleTime(5 * time.Minute). //连接生命周期
-			SetConnectTimeout(10 * time.Second). //连接超时时间
-			SetSocketTimeout(10 * time.Second)
+		o = options.Client().ApplyURI(uri).SetMaxPoolSize(maxPoolSize). //最大连接
+										SetMinPoolSize(minPoolSize).                                      //最小连接
+										SetMaxConnIdleTime(time.Duration(maxConnIdleTime) * time.Second). //连接空闲时间
+										SetConnectTimeout(time.Duration(connectTimeout) * time.Second).   //连接超时时间
+										SetSocketTimeout(time.Duration(socketTimeout) * time.Second)      //套接字超时时间
 	}
 
-
-	
 	if err := o.Validate(); err != nil {
 		return nil, err
 	}

+ 12 - 8
game/config/profile-gc.json

@@ -11,7 +11,7 @@
     },
     "nats": {
       "master_node_id": "m-master",
-      "address": "nats://s5.z100.vip:24222",
+      "address": "nats://127.0.0.1:4222",
       "reconnect_delay": 1,
       "max_reconnects": 5,
       "request_timeout": 10,
@@ -19,7 +19,7 @@
       "password": ""
     },
     "etcd": {
-      "end_points": "http://s5.z100.vip:22379",
+      "end_points": "http://127.0.0.1:2379",
       "@end_points": "dev.com:2379,dev1.com:2379",
       "prefix": "mhaya",
       "ttl": 5,
@@ -226,17 +226,21 @@
         "enable": true,
         "db_id": "game_db_1",
         "db_name": "db_mhaya",
-        "uri": "mongodb://s5.z100.vip:27019",
-        "tls": 1,
-        "maxClient": 500
+        "uri": "mongodb://127.0.0.1:27017",
+        "tls": 0,
+        "maxPoolSize": 500,
+        "minPoolSize": 20,
+        "maxConnIdleTime": 180,
+        "connectTimeout": 10,
+        "socketTimeout": 10
       }
     ]
   },
   "redis": {
-    "address": "s5.z100.vip:36379",
+    "address": "127.0.0.1:6379",
     "password": "",
     "db": 0,
-    "tls": 1
+    "tls": 0
   },
   "data_config": {
     "parser": "json",
@@ -249,7 +253,7 @@
     "redis": {
       "prefix_key": "data_config",
       "subscribe_key": "data_config_change",
-      "address": "redis:6379",
+      "address": "127.0.0.1:6379",
       "password": "",
       "db": 7
     }

+ 18 - 2
game/game_cluster/internal/mdb/component.go

@@ -1,13 +1,16 @@
 package mdb
 
 import (
+	"context"
 	"crypto/tls"
+	"fmt"
 	"github.com/go-redis/redis/v8"
 	mhayaMongo "github.com/mhaya/components/mongo"
 	clog "github.com/mhaya/logger"
 	cactor "github.com/mhaya/net/actor"
 	cprofile "github.com/mhaya/profile"
 	"go.mongodb.org/mongo-driver/mongo"
+	"strings"
 )
 
 type ActorDB struct {
@@ -45,17 +48,30 @@ func (p *ActorDB) OnInit() {
 			PreferServerCipherSuites: true,
 		}
 		RDB = redis.NewUniversalClient(&redis.UniversalOptions{
-			Addrs:     []string{redisConfig.GetString("address")},
+			Addrs:     strings.Split(redisConfig.GetString("address"), ","),
 			Password:  redisConfig.GetString("password"),
 			DB:        redisConfig.GetInt("db"),
 			TLSConfig: tlsConfig,
 		})
+		clog.Debugf("redis Addrs str: ", redisConfig.GetString("address"), ",")
+		split := strings.Split(redisConfig.GetString("address"), ",")
+		for i := 0; i < len(split); i++ {
+			if i > 0 {
+				fmt.Print(", ")
+			}
+			clog.Debugf("addr : %s", split[i])
+		}
+
+		err := RDB.Set(context.Background(), "test", 0, 0).Err()
+		clog.Errorf("redis client error %v:", err)
 	} else {
 		RDB = redis.NewUniversalClient(&redis.UniversalOptions{
-			Addrs:    []string{redisConfig.GetString("address")},
+			Addrs:    strings.Split(redisConfig.GetString("address"), ","),
 			Password: redisConfig.GetString("password"),
 			DB:       redisConfig.GetInt("db"),
 		})
+		err := RDB.Set(context.Background(), "test", 0, 0).Err()
+		clog.Errorf("redis client error %v:", err)
 	}
 
 	if p.App().NodeId() == "m-center" {

BIN
z-deploy/docker/center/center__linux__linux