From ef8cecd8707be62d65f3bca4791baff452a0732a Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 7 Sep 2023 15:45:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8E=8B=E6=B5=8B?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/robot/core.go | 7 +++++++ modules/robot/modulerobot_chat.go | 17 ++++++++++++++++- modules/robot/modulerobot_gm.go | 15 ++++++++++++++- modules/robot/modulerobot_shop.go | 24 ++++++++++++++++++++++++ modules/robot/options.go | 2 +- modules/robot/robot.go | 27 +++++++++++++++++++++------ modules/robot/robotmgrcomp.go | 1 + modules/robot/statisticalcomp.go | 1 + modules/sys/api_funcactivate.go | 5 +++-- 9 files changed, 88 insertions(+), 11 deletions(-) diff --git a/modules/robot/core.go b/modules/robot/core.go index 5ee0a8edb..17d510394 100644 --- a/modules/robot/core.go +++ b/modules/robot/core.go @@ -62,3 +62,10 @@ type MessageResp struct { resp proto.Message errdata *pb.ErrorData } + +type Pipeline struct { + Module string //模块名 + Exenum int32 //执行次数 + CurrNum int32 //当前已执行次数 + ErrNotStop bool //遇到错误是否中断 +} diff --git a/modules/robot/modulerobot_chat.go b/modules/robot/modulerobot_chat.go index 999cbd161..3bcd595e8 100644 --- a/modules/robot/modulerobot_chat.go +++ b/modules/robot/modulerobot_chat.go @@ -28,7 +28,22 @@ func (this *ModuleRobot_Chat) Receive(robot IRobot, stype string, message proto. //机器人执行流 func (this *ModuleRobot_Chat) DoPipeline(robot IRobot) (err error) { - + var ( + errdata *pb.ErrorData + usermodule *ModuleRobot_User + ) + usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User) + if _, errdata = robot.SendMessage("chat", "send", &pb.ChatSendReq{ + Avatar: usermodule.user.Avatar, + Uname: usermodule.user.Name, + Ulv: usermodule.user.Lv, + Channel: pb.ChatChannel_World, + Ctype: pb.ChatType_Text, + Content: fmt.Sprintf("你好!我是%s", robot.Account()), + }); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } return } diff --git a/modules/robot/modulerobot_gm.go b/modules/robot/modulerobot_gm.go index 12a0276d7..932ddfe41 100644 --- a/modules/robot/modulerobot_gm.go +++ b/modules/robot/modulerobot_gm.go @@ -1,6 +1,9 @@ package robot import ( + "errors" + "fmt" + "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "google.golang.org/protobuf/proto" @@ -23,7 +26,17 @@ func (this *ModuleRobot_GM) Receive(robot IRobot, stype string, message proto.Me //机器人执行流 func (this *ModuleRobot_GM) DoPipeline(robot IRobot) (err error) { - + var ( + errdata *pb.ErrorData + ) + if _, errdata = robot.SendMessage("gm", "cmd", &pb.GMCmdReq{Cmod: "bingo:attr,gold,1000000"}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + if _, errdata = robot.SendMessage("gm", "cmd", &pb.GMCmdReq{Cmod: "bingo:attr,diamond,1000000"}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } return } diff --git a/modules/robot/modulerobot_shop.go b/modules/robot/modulerobot_shop.go index 1a32717e4..f509ace48 100644 --- a/modules/robot/modulerobot_shop.go +++ b/modules/robot/modulerobot_shop.go @@ -33,7 +33,31 @@ func (this *ModuleRobot_Shop) Receive(robot IRobot, stype string, message proto. //机器人执行流 func (this *ModuleRobot_Shop) DoPipeline(robot IRobot) (err error) { + var ( + errdata *pb.ErrorData + usermodule *ModuleRobot_User + ) + usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User) + if _, errdata = robot.SendMessage("shop", "getlist", &pb.ShopGetListReq{ + SType: pb.ShopType_DiamondShop, + }); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + for _, v := range this.goods[pb.ShopType_DiamondShop] { + if v.LeftBuyNum > 0 && usermodule.user.Diamond >= int64(v.Consume[0].N) { + if _, errdata = robot.SendMessage("shop", "buy", &pb.ShopBuyReq{ + ShopType: pb.ShopType_DiamondShop, + Gid: v.Gid, + BuyNum: 1, + }); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + break + } + } return } diff --git a/modules/robot/options.go b/modules/robot/options.go index 70ae49343..0aee7f5b3 100644 --- a/modules/robot/options.go +++ b/modules/robot/options.go @@ -17,7 +17,7 @@ type ( RobotName string //机器人名称 RobotStart int32 //机器人初始下标 RobotLog bool - Pipeline []string //执行流水线 + Pipeline []Pipeline //执行流水线 } ) diff --git a/modules/robot/robot.go b/modules/robot/robot.go index 48d86f852..98bcc687d 100644 --- a/modules/robot/robot.go +++ b/modules/robot/robot.go @@ -31,8 +31,10 @@ type Robot struct { curreq string //当前请求 await chan *MessageResp modules map[core.M_Modules]IModuleRobot - pipeline []string //执行流水线 + cycle bool + pipeline []Pipeline //执行流水线 statistics []*RobotStatistics + wtaskerror error } func (this *Robot) Account() string { @@ -246,11 +248,24 @@ func (this *Robot) run() { module IModuleRobot err error ) - for _, v := range this.pipeline { - module = this.modules[core.M_Modules(v)] - if err = module.DoPipeline(this); err != nil { - log.Debug("[机器人 执行异常]", log.Field{Key: "Account", Value: this.account}, log.Field{Key: "module", Value: v}, log.Field{Key: "err", Value: err.Error()}) - break + for this.cycle { + this.cycle = false + for _, v := range this.pipeline { + if v.CurrNum < v.Exenum { + module = this.modules[core.M_Modules(v.Module)] + if err = module.DoPipeline(this); err != nil { + if this.debug { + log.Debug("[机器人 执行异常]", log.Field{Key: "Account", Value: this.account}, log.Field{Key: "module", Value: v}, log.Field{Key: "err", Value: err.Error()}) + } + if !v.ErrNotStop { + break + } + } + v.CurrNum++ + if v.CurrNum < v.Exenum { + this.cycle = true + } + } } } this.Close() diff --git a/modules/robot/robotmgrcomp.go b/modules/robot/robotmgrcomp.go index fcbceffb7..68e5a69a5 100644 --- a/modules/robot/robotmgrcomp.go +++ b/modules/robot/robotmgrcomp.go @@ -65,6 +65,7 @@ func (this *robotmgrComp) createRobot(index int32) { index: index, account: fmt.Sprintf("%s_%d", this.module.options.RobotName, this.module.options.RobotStart+index), serverId: this.module.options.ServerID, + cycle: true, pipeline: this.module.options.Pipeline, } if err = robot.Init(this.module.options.ServerAddr, robot); err != nil { diff --git a/modules/robot/statisticalcomp.go b/modules/robot/statisticalcomp.go index 7039eb3df..d15b7fbe3 100644 --- a/modules/robot/statisticalcomp.go +++ b/modules/robot/statisticalcomp.go @@ -52,6 +52,7 @@ func (this *statisticalComp) RobotFinishedTest(robot *Robot) { if this.endClientnum >= this.module.options.RobotTotalNum { //压测结束 this.OutReport() } + log.Debugf("完成测试:%s", robot.account) } //输出报表 diff --git a/modules/sys/api_funcactivate.go b/modules/sys/api_funcactivate.go index a7b0cb4d6..79be8b9b4 100644 --- a/modules/sys/api_funcactivate.go +++ b/modules/sys/api_funcactivate.go @@ -19,8 +19,9 @@ func (this *apiComp) FuncActivate(session comm.IUserSession, req *pb.SysFuncActi if opencfg != nil { if id := this.module.modelSys.validCond(session.GetUserId(), opencfg); id == "" { // 条件不满足 errdata = &pb.ErrorData{ - Code: pb.ErrorCode_OpenCondErr, - Title: pb.ErrorCode_OpenCondErr.ToString(), + Code: pb.ErrorCode_OpenCondErr, + Title: pb.ErrorCode_OpenCondErr.ToString(), + Message: req.Cid, } return } From 9000fc18dd6813ed365c61be480e688ac8617333 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 7 Sep 2023 17:08:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/build_windows.bat | 1 + bin/robot.txt | 29 +++++++++++++++++++++++++++++ modules/moonfantasy/configure.go | 2 +- modules/robot/client.go | 2 ++ modules/robot/robot.go | 3 ++- modules/robot/robotmgrcomp.go | 11 ++++++++++- 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 bin/robot.txt diff --git a/bin/build_windows.bat b/bin/build_windows.bat index 21bda5746..02e596ce2 100644 --- a/bin/build_windows.bat +++ b/bin/build_windows.bat @@ -7,3 +7,4 @@ go build -o ./bin/cmd.exe ./services/cmd/main.go go build -o ./bin/mainte.exe ./services/mainte/main.go go build -o ./bin/gateway.exe ./services/gateway/main.go go build -o ./bin/worker.exe ./services/worker/main.go +go build -o ./bin/robot.exe ./services/robot/main.go \ No newline at end of file diff --git a/bin/robot.txt b/bin/robot.txt new file mode 100644 index 000000000..e1ae981da --- /dev/null +++ b/bin/robot.txt @@ -0,0 +1,29 @@ +机器人总数: 1 +成功数量: 1 +失败数量: 0 +消息总吞吐量: 128 +---消息压测详情---------------------------------------------------------------------------------------------------- +消息名:hero.talentlist 请求次数:1 耗时最小:18 ms 耗时最大:18 ms 平均耗时:18.00ms 中位耗时:18.00ms +消息名:gm.cmd 请求次数:2 耗时最小:0 ms 耗时最大:29 ms 平均耗时:14.50ms 中位耗时:14.50ms +消息名:wtask.info 请求次数:1 耗时最小:40 ms 耗时最大:40 ms 平均耗时:40.00ms 中位耗时:40.00ms +消息名:wtask.finish 请求次数:16 耗时最小:34 ms 耗时最大:73 ms 平均耗时:45.38ms 中位耗时:43.00ms +消息名:wtask.battlefinish 请求次数:7 耗时最小:18 ms 耗时最大:109 ms 平均耗时:62.29ms 中位耗时:46.00ms +消息名:practice.info 请求次数:2 耗时最小:19 ms 耗时最大:30 ms 平均耗时:24.50ms 中位耗时:24.50ms +消息名:sys.funcactivate 请求次数:2 耗时最小:16 ms 耗时最大:19 ms 平均耗时:17.50ms 中位耗时:17.50ms +消息名:user.create 请求次数:1 耗时最小:87 ms 耗时最大:87 ms 平均耗时:87.00ms 中位耗时:87.00ms +消息名:mainline.info 请求次数:13 耗时最小:22 ms 耗时最大:32 ms 平均耗时:24.23ms 中位耗时:24.00ms +消息名:mainline.levelpass 请求次数:6 耗时最小:22 ms 耗时最大:25 ms 平均耗时:23.83ms 中位耗时:24.00ms +消息名:practice.practice 请求次数:1 耗时最小:24 ms 耗时最大:24 ms 平均耗时:24.00ms 中位耗时:24.00ms +消息名:wtask.completecondi 请求次数:3 耗时最小:26 ms 耗时最大:28 ms 平均耗时:27.00ms 中位耗时:27.00ms +消息名:chat.send 请求次数:10 耗时最小:14 ms 耗时最大:17 ms 平均耗时:15.70ms 中位耗时:15.50ms +消息名:shop.getlist 请求次数:10 耗时最小:16 ms 耗时最大:27 ms 平均耗时:19.50ms 中位耗时:19.00ms +消息名:wtask.accept 请求次数:17 耗时最小:23 ms 耗时最大:36 ms 平均耗时:27.47ms 中位耗时:27.00ms +消息名:sys.funcgetlist 请求次数:1 耗时最小:62 ms 耗时最大:62 ms 平均耗时:62.00ms 中位耗时:62.00ms +消息名:hero.list 请求次数:1 耗时最小:29 ms 耗时最大:29 ms 平均耗时:29.00ms 中位耗时:29.00ms +消息名:items.getlist 请求次数:1 耗时最小:23 ms 耗时最大:23 ms 平均耗时:23.00ms 中位耗时:23.00ms +消息名:hero.drawcard 请求次数:10 耗时最小:50 ms 耗时最大:75 ms 平均耗时:62.90ms 中位耗时:60.00ms +消息名:mainline.challenge 请求次数:7 耗时最小:48 ms 耗时最大:51 ms 平均耗时:49.71ms 中位耗时:50.00ms +消息名:mainline.challengeover 请求次数:7 耗时最小:82 ms 耗时最大:166 ms 平均耗时:128.86ms 中位耗时:152.00ms +消息名:user.login 请求次数:1 耗时最小:764 ms 耗时最大:764 ms 平均耗时:764.00ms 中位耗时:764.00ms +消息名:wtask.battlestart 请求次数:7 耗时最小:17 ms 耗时最大:29 ms 平均耗时:23.29ms 中位耗时:23.00ms +消息名:equipment.getlist 请求次数:1 耗时最小:19 ms 耗时最大:19 ms 平均耗时:19.00ms 中位耗时:19.00ms diff --git a/modules/moonfantasy/configure.go b/modules/moonfantasy/configure.go index 83c2e2427..a88475af2 100644 --- a/modules/moonfantasy/configure.go +++ b/modules/moonfantasy/configure.go @@ -84,7 +84,7 @@ func (this *configureComp) GettriggerData(ptypes int32) (result *cfg.GameDreamla } else { if result, ok = v.(*cfg.GameDreamlandTrigger).GetDataMap()[ptypes]; !ok { err = fmt.Errorf("not found:%d ", ptypes) - this.module.Errorln(err) + // this.module.Errorln(err) return } } diff --git a/modules/robot/client.go b/modules/robot/client.go index e31b3b7e1..e70f6c004 100644 --- a/modules/robot/client.go +++ b/modules/robot/client.go @@ -1,6 +1,7 @@ package robot import ( + "fmt" "go_dreamfactory/pb" "sync" "sync/atomic" @@ -88,6 +89,7 @@ locp: } func (this *Client) WriteMsg(msg *pb.UserMessage) (err error) { if atomic.LoadInt32(&this.state) != 1 { + err = fmt.Errorf("Client state closed !") return } var ( diff --git a/modules/robot/robot.go b/modules/robot/robot.go index 98bcc687d..b2334bb32 100644 --- a/modules/robot/robot.go +++ b/modules/robot/robot.go @@ -32,7 +32,7 @@ type Robot struct { await chan *MessageResp modules map[core.M_Modules]IModuleRobot cycle bool - pipeline []Pipeline //执行流水线 + pipeline []*Pipeline //执行流水线 statistics []*RobotStatistics wtaskerror error } @@ -248,6 +248,7 @@ func (this *Robot) run() { module IModuleRobot err error ) + for this.cycle { this.cycle = false for _, v := range this.pipeline { diff --git a/modules/robot/robotmgrcomp.go b/modules/robot/robotmgrcomp.go index 68e5a69a5..1a8d3ffaf 100644 --- a/modules/robot/robotmgrcomp.go +++ b/modules/robot/robotmgrcomp.go @@ -66,8 +66,17 @@ func (this *robotmgrComp) createRobot(index int32) { account: fmt.Sprintf("%s_%d", this.module.options.RobotName, this.module.options.RobotStart+index), serverId: this.module.options.ServerID, cycle: true, - pipeline: this.module.options.Pipeline, + pipeline: make([]*Pipeline, 0), } + + for _, v := range this.module.options.Pipeline { + robot.pipeline = append(robot.pipeline, &Pipeline{ + Module: v.Module, + Exenum: v.Exenum, + ErrNotStop: v.ErrNotStop, + }) + } + if err = robot.Init(this.module.options.ServerAddr, robot); err != nil { this.module.statisticalComp.AddFailClient(robot, err) return