소스 검색

压测提交

liliang 6 달 전
부모
커밋
167d64c8d5

+ 12 - 10
components/mongo/component.go

@@ -63,13 +63,14 @@ func (s *Component) Init() {
 				id              = item.GetString("db_id")
 				dbName          = item.GetString("db_name")
 				uri             = item.GetString("uri")
-				timeout         = time.Duration(item.GetInt64("timeout", 3)) * time.Second
+				timeout         = time.Duration(item.GetInt64("timeout", 10)) * 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")
+				setReplicaSet   = item.GetString("setReplicaSet")
 			)
 
 			for _, key := range mongoIdList.Keys() {
@@ -82,7 +83,7 @@ func (s *Component) Init() {
 					panic(fmt.Sprintf("[dbName = %s] is disabled!", dbName))
 				}
 
-				db, err := CreateDatabase(uri, dbName, tlsEnable, uint64(maxPoolSize), uint64(minPoolSize), maxConnIdleTime, connectTimeout, socketTimeout, timeout)
+				db, err := CreateDatabase(uri, setReplicaSet, 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))
 				}
@@ -94,7 +95,7 @@ func (s *Component) Init() {
 	}
 }
 
-func CreateDatabase(uri, dbName string, tlsEnable int, maxPoolSize uint64, minPoolSize uint64, maxConnIdleTime int, connectTimeout, socketTimeout int, timeout ...time.Duration) (*mongo.Database, error) {
+func CreateDatabase(uri, setReplicaSet, 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,15 +105,16 @@ func CreateDatabase(uri, dbName string, tlsEnable int, maxPoolSize uint64, minPo
 	var o *options.ClientOptions
 	if tlsEnable == 1 {
 		tlsConfig := &tls.Config{
-			MinVersion:               tls.VersionTLS12,
-			PreferServerCipherSuites: true,
+			//MinVersion:               tls.VersionTLS12,
+			//PreferServerCipherSuites: true,
+			InsecureSkipVerify: true,
 		}
 
-		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) //套接字超时时间
+		o = options.Client().ApplyURI(uri).SetReplicaSet(setReplicaSet).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(maxPoolSize). //最大连接
 										SetMinPoolSize(minPoolSize).                                      //最小连接

+ 7 - 7
components/mongo/go.mod

@@ -6,27 +6,27 @@ toolchain go1.22.4
 
 require (
 	github.com/mhaya v1.3.13
-	go.mongodb.org/mongo-driver v1.12.1
+	go.mongodb.org/mongo-driver v1.17.1
 )
 
 require (
-	github.com/golang/snappy v0.0.1 // indirect
+	github.com/golang/snappy v0.0.4 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
 	github.com/klauspost/compress v1.17.0 // indirect
 	github.com/lestrrat-go/strftime v1.0.6 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
-	github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
+	github.com/montanaflynn/stats v0.7.1 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
 	github.com/xdg-go/pbkdf2 v1.0.0 // indirect
 	github.com/xdg-go/scram v1.1.2 // indirect
 	github.com/xdg-go/stringprep v1.0.4 // indirect
-	github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
+	github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
 	go.uber.org/multierr v1.10.0 // indirect
 	go.uber.org/zap v1.26.0 // indirect
-	golang.org/x/crypto v0.21.0 // indirect
-	golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
-	golang.org/x/text v0.14.0 // indirect
+	golang.org/x/crypto v0.26.0 // indirect
+	golang.org/x/sync v0.8.0 // indirect
+	golang.org/x/text v0.17.0 // indirect
 	google.golang.org/protobuf v1.33.0 // indirect
 )
 

+ 7 - 0
components/mongo/go.sum

@@ -4,6 +4,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
 github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
+github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
@@ -24,6 +25,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
 github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
 github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
+github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -39,9 +41,11 @@ github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6
 github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
+github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
 go.mongodb.org/mongo-driver v1.12.1 h1:nLkghSU8fQNaK7oUmDhQFsnrtcoNy7Z6LVFKsEecqgE=
 go.mongodb.org/mongo-driver v1.12.1/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ=
+go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
 go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
 go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
 go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
@@ -53,6 +57,7 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0
 golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
 golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
 golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
+golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -61,6 +66,7 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -78,6 +84,7 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
 golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
 golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
+golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

+ 52 - 51
components/mongo/mongo_test.go

@@ -1,53 +1,54 @@
 package mhayaMongo
 
-import (
-	"context"
-	"fmt"
-	"testing"
-
-	clog "github.com/mhaya/logger"
-	"go.mongodb.org/mongo-driver/bson"
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-type Student struct {
-	Name string
-	Age  int
-}
-
-func TestConnect(t *testing.T) {
-	clog.Info("test connect mongodb")
-
-	uri := "mongodb://localhost:27017"
-	dbName := "test"
-
-	mdb, err := CreateDatabase(uri, dbName)
-	if err != nil {
-		clog.Warn(err)
-		return
-	}
-
-	collection := mdb.Collection("numbers")
-
-	student := &Student{
-		Name: "aaa222",
-		Age:  111,
-	}
-
-	res, err := collection.InsertOne(context.Background(), student)
-	insertID := res.InsertedID
-	clog.Infof("id = %v, err = %v", insertID, err)
-
-	//id, _ := primitive.ObjectIDFromHex("649160b6c637f5773cc1e818")
-	id, ok := insertID.(primitive.ObjectID)
-	if !ok {
-		return
-	}
-
-	findFilter := bson.M{"_id": id}
-	findResult := collection.FindOne(context.Background(), findFilter)
-
-	findStudent := Student{}
-	findResult.Decode(&findStudent)
-	fmt.Println(findStudent)
-}
+//
+//import (
+//	"context"
+//	"fmt"
+//	"testing"
+//
+//	clog "github.com/mhaya/logger"
+//	"go.mongodb.org/mongo-driver/bson"
+//	"go.mongodb.org/mongo-driver/bson/primitive"
+//)
+//
+//type Student struct {
+//	Name string
+//	Age  int
+//}
+//
+//func TestConnect(t *testing.T) {
+//	clog.Info("test connect mongodb")
+//
+//	uri := "mongodb://localhost:27017"
+//	dbName := "test"
+//
+//	mdb, err := CreateDatabase(uri, dbName)
+//	if err != nil {
+//		clog.Warn(err)
+//		return
+//	}
+//
+//	collection := mdb.Collection("numbers")
+//
+//	student := &Student{
+//		Name: "aaa222",
+//		Age:  111,
+//	}
+//
+//	res, err := collection.InsertOne(context.Background(), student)
+//	insertID := res.InsertedID
+//	clog.Infof("id = %v, err = %v", insertID, err)
+//
+//	//id, _ := primitive.ObjectIDFromHex("649160b6c637f5773cc1e818")
+//	id, ok := insertID.(primitive.ObjectID)
+//	if !ok {
+//		return
+//	}
+//
+//	findFilter := bson.M{"_id": id}
+//	findResult := collection.FindOne(context.Background(), findFilter)
+//
+//	findStudent := Student{}
+//	findResult.Decode(&findStudent)
+//	fmt.Println(findStudent)
+//}

+ 1 - 1
const/const.go

@@ -5,7 +5,7 @@ import (
 )
 
 const (
-	version = "1.0.37"
+	version = "1.0.56"
 )
 
 var logo = `

+ 2 - 1
game/config/profile-gc.json

@@ -246,6 +246,7 @@
         "db_id": "game_db_1",
         "db_name": "db_mhaya",
         "uri": "mongodb://127.0.0.1:27017",
+        "setReplicaSet": "rs0",
         "tls": 0,
         "maxPoolSize": 500,
         "minPoolSize": 20,
@@ -256,7 +257,7 @@
     ]
   },
   "redis": {
-    "address": "s5.z100.vip:36379",
+    "address": "127.0.0.1:6379",
     "password": "",
     "db": 0,
     "tls": 0

+ 90 - 0
game/game_cluster/nodes/db/db/sync.go

@@ -0,0 +1,90 @@
+package db
+
+//
+//import (
+//	"context"
+//	"fmt"
+//	cprofile "github.com/mhaya/profile"
+//	"go.mongodb.org/mongo-driver/mongo"
+//	"go.mongodb.org/mongo-driver/mongo/options"
+//	"log"
+//)
+//
+//const (
+//	// MongoDB连接信息
+//	mongoURI = "mongodb://mhaya:AaPXRfQLqMe6ns7@boss-io.cluster-c5uigyoe8wcg.ap-southeast-1.docdb.amazonaws.com:27017/?replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false&tls=true&tlsInsecure=true"
+//
+//	databaseName     = "db_mhaya"
+//	collectionName   = "numbers"
+//	totalRecords     = 100000
+//	progressInterval = totalRecords / 100 // 每插入1%的数据就打印一次
+//	batchSize        = 1000
+//)
+//
+//type (
+//	// HashDb hash by group id
+//	HashDb func(dbMaps map[string]*mongo.Database) string
+//)
+//
+////func GetMongoClient() *mongo.Client {
+////	// 连接到 MongoDB
+////	client, err := mongo.NewClient(options.Client().ApplyURI(mongoURI))
+////	if err != nil {
+////		log.Fatalf("无法连接到 MongoDB: %v", err)
+////	}
+////
+////	// 连接到数据库
+////	err = client.Connect(context.Background())
+////	if err != nil {
+////		log.Fatalf("无法连接到数据库: %v", err)
+////	}
+////	defer client.Disconnect(context.Background())
+////
+////	// 批量插入数据并打印进度
+////	//insertDataWithProgress(client, data)
+////
+////	// 插入完成'
+////	fmt.Println("数据插入完成!")
+////	return client
+////}
+//
+//func GetMongoClient() *mongo.Client {
+//
+//	mongoConfig := cprofile.GetConfig("mongo")
+//	if mongoConfig.LastError() != nil {
+//		panic("`mongo` property not exists in profile file.")
+//	}
+//
+//	var client *mongo.Client
+//
+//	var dbMap map[string]map[string]*mongo.Database
+//	for _, groupId := range mongoConfig.Keys() {
+//		dbMap[groupId] = make(map[string]*mongo.Database)
+//
+//		dbGroup := mongoConfig.GetConfig(groupId)
+//		for i := 0; i < dbGroup.Size(); i++ {
+//			item := dbGroup.GetConfig(i)
+//
+//			var (
+//				uri = item.GetString("uri")
+//			)
+//
+//			// 连接到 MongoDB
+//			client, err := mongo.NewClient(options.Client().ApplyURI(uri))
+//			if err != nil {
+//				log.Fatalf("无法连接到 MongoDB: %v", err)
+//			}
+//
+//			// 连接到数据库
+//			err = client.Connect(context.Background())
+//			if err != nil {
+//				log.Fatalf("无法连接到数据库: %v", err)
+//			}
+//			defer client.Disconnect(context.Background())
+//
+//			// 插入完成'
+//			fmt.Println("数据插入完成!")
+//		}
+//	}
+//	return client
+//}

+ 74 - 9
game/game_cluster/nodes/db/module/actor_save_db.go

@@ -12,7 +12,6 @@ import (
 	"github.com/mhaya/net/parser/simple"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/mongo"
-	"log"
 	"time"
 )
 
@@ -36,10 +35,11 @@ func (p *ActorSaves) saveAccountDB1() {
 }
 
 func (p *ActorSaves) savePlayerDB1() {
-	go p.savePlayerDB()
+	go p.savePlayerDBTwo()
 }
 
 func (p *ActorSaves) saveAccountDB() {
+	clog.Debugf("saveAccountDb ==> start()")
 	key := 0
 	newKey := 0
 	bulkUpdOps := []mongo.WriteModel{}
@@ -53,7 +53,7 @@ func (p *ActorSaves) saveAccountDB() {
 	for k, v := range newAccounts {
 		var account models.Account
 		if v == "1" {
-			if newKey < 10000 {
+			if newKey < 1000 {
 				acc, _ := mdb.RDB.Get(ctx, fmt.Sprintf("%v:%v", constant.CNameAccount, k)).Bytes()
 				if len(acc) > 0 {
 					err := jsoniter.Unmarshal(acc, &account)
@@ -71,7 +71,7 @@ func (p *ActorSaves) saveAccountDB() {
 			}
 			newKey++
 		} else {
-			if key < 5000 {
+			if key < 1000 {
 				acc, _ := mdb.RDB.Get(ctx, fmt.Sprintf("%v:%v", constant.CNameAccount, k)).Bytes()
 				if len(acc) > 0 {
 					err := jsoniter.Unmarshal(acc, &account)
@@ -86,7 +86,7 @@ func (p *ActorSaves) saveAccountDB() {
 				key++
 			}
 		}
-		if newKey > 10000 || key > 5000 {
+		if newKey > 1000 || key > 1000 {
 			break
 		}
 	}
@@ -102,7 +102,7 @@ func (p *ActorSaves) saveAccountDB() {
 	if len(bulkInsAccountOps) > 0 {
 		_, err := mdb.MDB.Collection(constant.CNameAccount).BulkWrite(context.Background(), bulkInsAccountOps)
 		if err != nil {
-			log.Fatalf("Bulk write failed: %v", err)
+			clog.Errorf("Bulk write failed: %v", err)
 		}
 		mdb.RDB.HDel(ctx, constant.NewAccounts, insAccount...)
 		clog.Infof("insert account to db count=%v", len(bulkInsAccountOps))
@@ -110,22 +110,24 @@ func (p *ActorSaves) saveAccountDB() {
 	if len(bulkInsPlayerOps) > 0 {
 		_, err := mdb.MDB.Collection(constant.CNamePlayer).BulkWrite(context.Background(), bulkInsPlayerOps)
 		if err != nil {
-			log.Fatalf("Bulk write failed: %v", err)
+			clog.Errorf("Bulk write failed: %v", err)
 		}
 		mdb.RDB.HDel(ctx, constant.NewPlayers, insPlayer...)
 		clog.Infof("insert player info to db count=%v", len(bulkInsPlayerOps))
 	}
 
+	clog.Debugf("saveAccountDb ==> end()")
 }
 
 func (p *ActorSaves) savePlayerDB() {
+	clog.Debugf("saveAccountDb ==> start()")
 	key := 0
 	bulkUpdOps := []mongo.WriteModel{}
 	ctx := context.Background()
 	newPlayers := mdb.RDB.HGetAll(ctx, constant.NewPlayers).Val()
 	updPlayer := []string{}
 	for k, _ := range newPlayers {
-		if key < 5000 {
+		if key < 1000 {
 			var player models.Player
 			acc, _ := mdb.RDB.Get(ctx, fmt.Sprintf("%v:%v", constant.CNamePlayer, k)).Bytes()
 			if len(acc) > 0 {
@@ -140,7 +142,7 @@ func (p *ActorSaves) savePlayerDB() {
 			updPlayer = append(updPlayer, player.OpenId)
 		}
 		key++
-		if key > 5000 {
+		if key > 1000 {
 			break
 		}
 	}
@@ -153,6 +155,69 @@ func (p *ActorSaves) savePlayerDB() {
 		mdb.RDB.HDel(ctx, constant.NewPlayers, updPlayer...)
 		clog.Infof("update player info to db count=%v", len(bulkUpdOps))
 	}
+	clog.Debugf("saveAccountDb ==> end()")
+
+}
+
+func (p *ActorSaves) savePlayerDBTwo() {
+	clog.Debugf("savePlayerDBTwo ==> start()")
+	key := 0
+	bulkUpdOps := []mongo.WriteModel{}
+	ctx := context.Background() // 可以考虑传入 ctx,提升代码的灵活性
+	newPlayers := mdb.RDB.HGetAll(ctx, constant.NewPlayers).Val()
+	updPlayer := []string{}
+
+	// 使用 goroutines 并发处理玩家更新
+	for k, _ := range newPlayers {
+		if key >= 1000 {
+			break // 优化了循环条件,提前退出
+		}
+
+		var player models.Player
+		acc, err := mdb.RDB.Get(ctx, fmt.Sprintf("%v:%v", constant.CNamePlayer, k)).Bytes()
+		if err != nil {
+			// 记录 Redis 错误并继续
+			clog.Errorf("Failed to get player %v from Redis: %v", k, err)
+			continue
+		}
+
+		if len(acc) > 0 {
+			err = jsoniter.Unmarshal(acc, &player)
+			if err != nil {
+				clog.Errorf("Failed to unmarshal player %v: %v", k, err)
+				continue
+			}
+		}
+
+		// 构建 MongoDB 更新操作
+		filter := bson.M{"openId": player.OpenId}
+		update := bson.M{"$set": player} // 这里可以直接使用 player,而不需要取地址
+
+		// 添加到 Bulk 操作队列
+		bulkUpdOps = append(bulkUpdOps, mongo.NewUpdateOneModel().SetFilter(filter).SetUpdate(update))
+		updPlayer = append(updPlayer, player.OpenId)
+
+		key++
+	}
+
+	// 执行批量更新
+	if len(bulkUpdOps) > 0 {
+		_, err := mdb.MDB.Collection(constant.CNamePlayer).BulkWrite(ctx, bulkUpdOps)
+		if err != nil {
+			clog.Errorf("Bulk write to MongoDB failed: %v", err)
+			return // 如果 bulk 更新失败,停止执行后续操作
+		}
+
+		// 删除 Redis 中的玩家数据
+		_, err = mdb.RDB.HDel(ctx, constant.NewPlayers, updPlayer...).Result()
+		if err != nil {
+			clog.Errorf("Failed to delete players from Redis: %v", err)
+		}
+
+		clog.Infof("Updated player info to MongoDB, count=%v", len(bulkUpdOps))
+	}
+	clog.Debugf("savePlayerDBTwo ==> start()")
+
 }
 
 /*func (p *ActorSaves) OnFindChild(msg *cfacade.Message) (cfacade.IActor, bool) {

+ 11 - 10
game/game_cluster/nodes/game/module/player/actor_player.go

@@ -33,15 +33,16 @@ type (
 	// actorPlayer 每位登录的玩家对应一个子actor
 	actorPlayer struct {
 		pomelo.ActorBase
-		isOnline   bool // 玩家是否在线
-		playerId   string
-		uid        int64
-		targetPath string
-		index      int
-		dirty      bool
-		exitTime   time.Duration
-		Player     *models.Player
-		Account    *models.Account
+		isOnline    bool // 玩家是否在线
+		playerId    string
+		uid         int64
+		targetPath  string
+		index       int
+		dirty       bool
+		exitTime    time.Duration
+		Player      *models.Player
+		Account     *models.Account
+		TonWallFlag bool
 	}
 
 	CachePlayer struct {
@@ -117,7 +118,7 @@ func (p *actorPlayer) OnInit() {
 
 	//p.Timer().Add(5*time.Second, p.initHourly)
 
-	//p.Timer().AddOnce(5*time.Second, p.getAndUpdateAvatar) //排行榜头像
+	p.Timer().AddOnce(5*time.Second, p.getAndUpdateAvatar) //排行榜头像
 
 	//p.Timer().Add(30*time.Second, p.updPassWordTime)
 

+ 3 - 3
game/game_cluster/nodes/game/module/player/claim.go

@@ -14,9 +14,9 @@ import (
 )
 
 func (p *actorPlayer) claim(req *param.ClaimReq) (*param.ChangeData, int32) {
-	//if !p.isOnline {
-	//	return nil, code.PlayerNotLogin
-	//}
+	if !p.isOnline {
+		return nil, code.PlayerNotLogin
+	}
 	var resp *param.ChangeData
 	var code int32
 	switch req.Tp {

+ 8 - 6
game/game_cluster/nodes/game/module/player/jump.go

@@ -16,17 +16,19 @@ func (p *actorPlayer) jump(req *param.JumpReq) (*param.JumpResp, int32) {
 	ret := p.Player.FinishAchieveTaskByType1(req.Tp)
 	if ret {
 		p.dirty = true
+		p.TonWallFlag = true
 		clog.Debugf("jump return true openid = %s", p.Player.OpenId)
 		return &param.JumpResp{Dirty: true}, code.OK
 	}
 	clog.Debugf("jump return flase openid = %s", p.Player.OpenId)
+	p.TonWallFlag = false
 	return &param.JumpResp{Dirty: false}, code.OK
 }
 
 func (p *actorPlayer) savex(req *param.SaveXReq) (*param.ChangeData, int32) {
-	//if !p.isOnline {
-	//	return nil, code.PlayerNotLogin
-	//}
+	if !p.isOnline {
+		return nil, code.PlayerNotLogin
+	}
 
 	if p.Player.XID == req.Twitter {
 		return nil, code.XAccountAlreadyExistsError
@@ -52,9 +54,9 @@ func (p *actorPlayer) savex(req *param.SaveXReq) (*param.ChangeData, int32) {
 }
 
 func (p *actorPlayer) savetonwall(req *param.SaveTonWallReq) int32 {
-	//if !p.isOnline {
-	//	return code.PlayerNotLogin
-	//}
+	if !p.isOnline {
+		return code.PlayerNotLogin
+	}
 
 	/*	errCode := p.VerifyPwd(req.PassWord)
 		if errCode > 0 {

+ 6 - 6
game/game_cluster/nodes/game/module/player/rank.go

@@ -14,9 +14,9 @@ import (
 )
 
 func (p *actorPlayer) rank(req *param.GetRankReq) (*param.GetRankResp, int32) {
-	//if !p.isOnline {
-	//	return nil, code.LoginError
-	//}
+	if !p.isOnline {
+		return nil, code.LoginError
+	}
 	var resp param.GetRankResp
 	rankList := models.GetRankList(req.Id, req.Tp)
 	resp.Ranks = rankList
@@ -62,9 +62,9 @@ func (p *actorPlayer) rank(req *param.GetRankReq) (*param.GetRankResp, int32) {
 }
 
 func (p *actorPlayer) countryRank() (*param.GetCountryRankResp, int32) {
-	//if !p.isOnline {
-	//	return nil, code.LoginError
-	//}
+	if !p.isOnline {
+		return nil, code.LoginError
+	}
 
 	var resp param.GetCountryRankResp
 	countryMap := make(map[string]*data.ContryConfigRow, 0)

+ 1 - 1
game/game_cluster/nodes/game/module/player/start.go

@@ -53,7 +53,7 @@ func (p *actorPlayer) start() (*models.HomeData, int32) {
 		Item:         p.Player.Item,
 		FirstItem:    p.Player.FirstClaimReward,
 		RocketLv:     rocketLv,
-		Dirty:        p.dirty,
+		Dirty:        p.TonWallFlag,
 		TotalIcorme:  totalIcorme,
 		ChatIDName:   botConfig.Params.ChatIDName,
 		BtUserName:   botConfig.Params.BtUserName,

+ 3 - 3
game/game_cluster/robot_client/main.go

@@ -17,9 +17,9 @@ import (
 func main() {
 
 	// 定义命令行标志
-	userOffset := flag.Int("userOffset", 500000, "用户偏移量")
-	count := flag.Int("count", 200000, "请求总数")
-	qps := flag.Int("qps", 500, "最大并发数")
+	userOffset := flag.Int("userOffset", 0, "用户偏移量")
+	count := flag.Int("count", 10000, "请求总数")
+	qps := flag.Int("qps", 200, "最大并发数")
 	url := flag.String("url", "http://127.0.0.1:20000", "请求url")
 	url1 := flag.String("url1", "http://127.0.0.1:20001", "请求url")
 	url2 := flag.String("url2", "http://127.0.0.1:20002", "请求url")

+ 2 - 2
game/go.mod

@@ -21,7 +21,7 @@ require (
 	github.com/oschwald/geoip2-golang v1.11.0
 	github.com/spf13/cast v1.5.1
 	github.com/urfave/cli/v2 v2.25.7
-	go.mongodb.org/mongo-driver v1.16.1
+	go.mongodb.org/mongo-driver v1.17.1
 	golang.org/x/crypto v0.26.0
 	google.golang.org/protobuf v1.34.1
 	gorm.io/driver/mysql v1.5.7
@@ -79,7 +79,7 @@ require (
 	github.com/xdg-go/scram v1.1.2 // indirect
 	github.com/xdg-go/stringprep v1.0.4 // indirect
 	github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
-	github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
+	github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
 	go.etcd.io/etcd/api/v3 v3.5.16 // indirect
 	go.etcd.io/etcd/client/pkg/v3 v3.5.16 // indirect
 	go.etcd.io/etcd/client/v3 v3.5.16 // indirect

+ 4 - 0
game/go.sum

@@ -171,6 +171,8 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT
 github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
+github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
+github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
 github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
@@ -182,6 +184,8 @@ go.etcd.io/etcd/client/v3 v3.5.16 h1:sSmVYOAHeC9doqi0gv7v86oY/BTld0SEFGaxsU9eRhE
 go.etcd.io/etcd/client/v3 v3.5.16/go.mod h1:X+rExSGkyqxvu276cr2OwPLBaeqFu1cIl4vmRjAD/50=
 go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8=
 go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
+go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
+go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
 go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
 go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
 go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=

+ 3 - 3
net/actor/system.go

@@ -32,9 +32,9 @@ func NewSystem() *System {
 		localInvokeFunc:  InvokeLocalFunc,
 		remoteInvokeFunc: InvokeRemoteFunc,
 		wg:               &sync.WaitGroup{},
-		callTimeout:      10 * time.Second,
-		arrivalTimeOut:   2000,
-		executionTimeout: 2000,
+		callTimeout:      60 * time.Second,
+		arrivalTimeOut:   30000,
+		executionTimeout: 30000,
 	}
 
 	return system