From 5cec318799737d70e7952140b1a4953b8908d12a Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sat, 3 Dec 2022 01:53:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_monsterformat.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/json/game_monsterformat.json b/bin/json/game_monsterformat.json index 24efe8e0d..b82f265d0 100644 --- a/bin/json/game_monsterformat.json +++ b/bin/json/game_monsterformat.json @@ -74286,7 +74286,7 @@ "Id": 700021, "pos": 4, "captainId": 0, - "monster": 340045, + "monster": 250015, "lv": 15, "hppro": 1, "atkpro": 1, From 282f3eb1bb906ee45b730d06df80e26e49d0e939 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 5 Dec 2022 08:41:05 +0800 Subject: [PATCH 2/3] update --- modules/gateway/module.go | 2 +- stress/server/golink/websocket_link.go | 2 ++ stress/server/statistics/statistics.go | 30 +++++++++++++++----------- stress/stress.go | 28 ++---------------------- 4 files changed, 22 insertions(+), 40 deletions(-) diff --git a/modules/gateway/module.go b/modules/gateway/module.go index d3b11cba2..4c679fd58 100644 --- a/modules/gateway/module.go +++ b/modules/gateway/module.go @@ -62,7 +62,7 @@ func (this *Gateway) Init(service core.IService, module core.IModule, options co // Start 模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务 func (this *Gateway) Start() (err error) { - log.Debugf("dddd") + _name2Func := map[string]any{ // 注册用户绑定uid接口 登录成功后触发 string(comm.Rpc_GatewayAgentBind): this.agentMgr.Bind, diff --git a/stress/server/golink/websocket_link.go b/stress/server/golink/websocket_link.go index 26fe27e5c..8d5415465 100644 --- a/stress/server/golink/websocket_link.go +++ b/stress/server/golink/websocket_link.go @@ -61,6 +61,8 @@ end: // 保持连接 chWaitFor := make(chan int, 0) <-chWaitFor + //time.Sleep(15 * time.Millisecond) + //return } return } diff --git a/stress/server/statistics/statistics.go b/stress/server/statistics/statistics.go index 97b092dc5..c14fc1f5d 100644 --- a/stress/server/statistics/statistics.go +++ b/stress/server/statistics/statistics.go @@ -52,7 +52,7 @@ func InitLog() { if err := log.OnInit(op.Setting.Sys["log"]); err != nil { panic(fmt.Sprintf("Sys log Init err:%v", err)) } else { - log.Infof("ddddd Sys log Init success !") + log.Infof("stress Sys log Init success !") } } @@ -71,6 +71,7 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy requestTime uint64 // 请求总时间 maxTime uint64 // 最大时长 minTime uint64 // 最小时长 + curTime uint64 // 当前消耗时常 successNum uint64 // 成功处理数,code为0 failureNum uint64 // 处理失败数,code不为0 0 chanIDLen int // 并发数 @@ -90,8 +91,9 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy endTime := uint64(time.Now().UnixNano()) mutex.Lock() go calculateData(concurrent, processingTime, endTime-statTime, maxTime, minTime, successNum, failureNum, - chanIDLen, errCode, receivedBytes) + chanIDLen, errCode, receivedBytes, curTime) mutex.Unlock() + case <-stopChan: // 处理完成 return @@ -102,6 +104,7 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy for data := range ch { mutex.Lock() // fmt.Println("处理一条数据", data.ID, data.Time, data.IsSucceed, data.ErrCode) + curTime = data.Time processingTime = processingTime + data.Time if maxTime <= data.Time { maxTime = data.Time @@ -131,13 +134,14 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy } requestTimeList = append(requestTimeList, data.Time) mutex.Unlock() + } // 数据全部接受完成,停止定时输出统计数据 stopChan <- true endTime := uint64(time.Now().UnixNano()) requestTime = endTime - statTime calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum, chanIDLen, errCode, - receivedBytes) + receivedBytes, curTime) log.Infof("\n\n") log.Infof("************************* 结果 stat ****************************") @@ -160,15 +164,15 @@ func printTop(requestTimeList []uint64) { all := tools.MyUint64List{} all = requestTimeList sort.Sort(all) - log.Infof("tp90:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.90)]/1e6))) - log.Infof("tp95:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.95)]/1e6))) - log.Infof("tp99:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.99)]/1e6))) + // log.Infof("tp90:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.90)]/1e6))) + // log.Infof("tp95:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.95)]/1e6))) + // log.Infof("tp99:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.99)]/1e6))) } // calculateData 计算数据 func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum uint64, - chanIDLen int, errCode *sync.Map, receivedBytes int64) { + chanIDLen int, errCode *sync.Map, receivedBytes int64, curTime uint64) { if processingTime == 0 { processingTime = 1 } @@ -190,7 +194,7 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su // 纳秒=>毫秒 maxTimeFloat = float64(maxTime) / 1e6 minTimeFloat = float64(minTime) / 1e6 - requestTimeFloat = float64(requestTime) / 1e9 + requestTimeFloat = float64(curTime) / 1e6 // float64(requestTime) / 1e9 // 打印的时长都为毫秒 table(successNum, failureNum, errCode, qps, averageTime, maxTimeFloat, minTimeFloat, requestTimeFloat, chanIDLen, receivedBytes) @@ -200,9 +204,9 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su func header() { log.Infof("\n\n") // 打印的时长都为毫秒 总请数 - log.Infof("─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────┬────────┬────────") - log.Infof(" 耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│下载字节│字节每秒│ 状态码") - log.Infof("─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────┼────────┼────────") + log.Infof("─────┬───────┬───────┬───────┬────────┬───────────┬───────────┬───────────┬────────┬─────────┬───────") + log.Infof(" 耗时│ 并发数│ 成功数│ 失败数 │ qps │最长耗时 ms │最短耗时 ms│平均耗时 ms│下载字节│ 字节每秒 │ 状态码") + log.Infof("─────┼───────┼───────┼───────┼────────┼───────────┼───────────┼───────────┼────────┼─────────┼───────") return } @@ -212,8 +216,8 @@ func table(successNum, failureNum uint64, errCode *sync.Map, var ( speed int64 ) - if requestTimeFloat > 0 { - speed = int64(float64(receivedBytes) / requestTimeFloat) + if averageTime > 0 { + speed = int64(float64(receivedBytes) / averageTime * 1e6 / 8 / 1024) } else { speed = 0 } diff --git a/stress/stress.go b/stress/stress.go index 3dfa4b5fb..c03b5a2b7 100644 --- a/stress/stress.go +++ b/stress/stress.go @@ -9,12 +9,9 @@ import ( "go_dreamfactory/stress/model" "go_dreamfactory/stress/server" "go_dreamfactory/stress/server/statistics" - "io/ioutil" "runtime" "strings" "time" - - "gopkg.in/yaml.v2" ) // array 自定义数组参数 @@ -77,34 +74,13 @@ type Options struct { Setting core.ServiceSttings //服务参数配置 } -func newOptions(path string) *Options { - options := &Options{} - - yamlFile, err := ioutil.ReadFile(path) - if err != nil { - panic(fmt.Sprintf("读取服务配置【%s】文件失败err:%v:", options.ConfPath, err)) - } - err = yaml.Unmarshal(yamlFile, &options.Setting) - if err != nil { - panic(fmt.Sprintf("读取服务配置【%s】文件失败err:%v:", options.ConfPath, err)) - } - return options -} - //go:generate go build main.go func main() { runtime.GOMAXPROCS(cpuNumber) flag.Parse() statistics.InitLog() - // op := newOptions("./conf/stress_1.yaml") - // if err := log.OnInit(op.Setting.Sys["log"]); err != nil { - // panic(fmt.Sprintf("Sys log Init err:%v", err)) - // } else { - // log.Infof("Sys log Init success !") - // } - // log.Debugf("ddddd") - //go run .\main.go -c 10 -n 10 -u ws://10.0.5.101:7891/gateway - concurrency = 1 + + concurrency = 1000 totalNumber = 1 debugStr = "false" requestURL = "ws://10.0.0.9:7891/gateway" From 7ec319f40d66213ee83b5fb41bcced42526fb1d9 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 5 Dec 2022 10:04:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=8A=A0?= =?UTF-8?q?=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/user/model_expand.go | 6 +++++- modules/user/model_setting.go | 5 +++++ modules/user/model_sign.go | 4 ++++ modules/user/model_user.go | 9 +++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/user/model_expand.go b/modules/user/model_expand.go index bc51df2fa..6b4c7a99e 100644 --- a/modules/user/model_expand.go +++ b/modules/user/model_expand.go @@ -10,6 +10,7 @@ import ( "go_dreamfactory/utils" "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) // 记录一些扩展数据 @@ -22,6 +23,9 @@ func (this *ModelExpand) Init(service core.IService, module core.IModule, comp c this.TableName = comm.TableUserExpand err = this.MCompModel.Init(service, module, comp, options) this.module = module.(*User) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) return } @@ -35,7 +39,7 @@ func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err } else { if err = model.Get(uid, result); err != nil && mongo.ErrNoDocuments != err { this.module.Error("Cross Get", log.Fields{"uid": uid}) - return result,err + return result, err } } } else { diff --git a/modules/user/model_setting.go b/modules/user/model_setting.go index bc12aafd9..28b943d26 100644 --- a/modules/user/model_setting.go +++ b/modules/user/model_setting.go @@ -12,6 +12,8 @@ import ( "time" "github.com/spf13/cast" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) type ModelSetting struct { @@ -23,6 +25,9 @@ func (this *ModelSetting) Init(service core.IService, module core.IModule, comp this.TableName = comm.TableSetting err = this.MCompModel.Init(service, module, comp, options) this.module = module.(*User) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) return } diff --git a/modules/user/model_sign.go b/modules/user/model_sign.go index 15d462c76..96cd180af 100644 --- a/modules/user/model_sign.go +++ b/modules/user/model_sign.go @@ -11,6 +11,7 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) // 签到 @@ -23,6 +24,9 @@ func (this *ModelSign) Init(service core.IService, module core.IModule, comp cor this.TableName = comm.TableSign err = this.MCompModel.Init(service, module, comp, options) this.module = module.(*User) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) return } diff --git a/modules/user/model_user.go b/modules/user/model_user.go index cf145d411..46e93ad64 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -17,6 +17,7 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) type ModelUser struct { @@ -32,6 +33,14 @@ func (this *ModelUser) Init(service core.IService, module core.IModule, comp cor this.EventApp = event_v2.NewApp() this.EventApp.Listen(comm.EventUserChanged, this.ChangeExp) this.EventApp.Listen(comm.EventUserChanged, this.ChangeLevel) + // 通过uid创建索引 + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "name", Value: bsonx.Int32(1)}}, + }) return }