diff --git a/modules/robot/modulerobot_dailytask.go b/modules/robot/modulerobot_dailytask.go new file mode 100644 index 000000000..0a5a28d51 --- /dev/null +++ b/modules/robot/modulerobot_dailytask.go @@ -0,0 +1,54 @@ +package robot + +import ( + "errors" + "fmt" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//用户模块 机器人 +type ModuleRobot_Dailytask struct { + task []*pb.DBDailytaskGroupProgress +} + +func (this *ModuleRobot_Dailytask) Init() (err error) { + + return +} + +//接收到消息 +func (this *ModuleRobot_Dailytask) Receive(robot IRobot, stype string, message proto.Message) (err error) { + switch stype { + case "info": + resp := message.(*pb.DailytaskInfoResp) + this.task = resp.Task + break + } + return +} +func (this *ModuleRobot_Dailytask) OncePipeline(robot IRobot) (err error) { + var ( + errdata *pb.ErrorData + ) + if _, errdata = robot.SendMessage("dailytask", "info", &pb.DailytaskInfoReq{}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + + return +} + +//机器人执行流 +func (this *ModuleRobot_Dailytask) DoPipeline(robot IRobot) (err error) { + + return +} + +//做任务 +func (this *ModuleRobot_Dailytask) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { + + return +} diff --git a/modules/robot/modulerobot_dragon.go b/modules/robot/modulerobot_dragon.go new file mode 100644 index 000000000..01fdd2f7f --- /dev/null +++ b/modules/robot/modulerobot_dragon.go @@ -0,0 +1,54 @@ +package robot + +import ( + "errors" + "fmt" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//用户模块 机器人 +type ModuleRobot_Dragon struct { + dragons []*pb.DBDragon +} + +func (this *ModuleRobot_Dragon) Init() (err error) { + + return +} + +//接收到消息 +func (this *ModuleRobot_Dragon) Receive(robot IRobot, stype string, message proto.Message) (err error) { + switch stype { + case "getlist": + resp := message.(*pb.DragonGetListResp) + this.dragons = resp.Dragons + break + } + return +} +func (this *ModuleRobot_Dragon) OncePipeline(robot IRobot) (err error) { + var ( + errdata *pb.ErrorData + ) + if _, errdata = robot.SendMessage("dragon", "getlist", &pb.DragonGetListReq{}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + + return +} + +//机器人执行流 +func (this *ModuleRobot_Dragon) DoPipeline(robot IRobot) (err error) { + + return +} + +//做任务 +func (this *ModuleRobot_Dragon) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { + + return +} diff --git a/modules/robot/modulerobot_integral.go b/modules/robot/modulerobot_integral.go new file mode 100644 index 000000000..1407ca824 --- /dev/null +++ b/modules/robot/modulerobot_integral.go @@ -0,0 +1,54 @@ +package robot + +import ( + "errors" + "fmt" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//用户模块 机器人 +type ModuleRobot_Integral struct { + boos *pb.DBIntegralBoss +} + +func (this *ModuleRobot_Integral) Init() (err error) { + + return +} + +//接收到消息 +func (this *ModuleRobot_Integral) Receive(robot IRobot, stype string, message proto.Message) (err error) { + switch stype { + case "getlist": + resp := message.(*pb.IntegralGetListResp) + this.boos = resp.Data + break + } + return +} +func (this *ModuleRobot_Integral) OncePipeline(robot IRobot) (err error) { + var ( + errdata *pb.ErrorData + ) + if _, errdata = robot.SendMessage("integral", "getlist", &pb.IntegralGetListReq{}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + + return +} + +//机器人执行流 +func (this *ModuleRobot_Integral) DoPipeline(robot IRobot) (err error) { + + return +} + +//做任务 +func (this *ModuleRobot_Integral) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { + + return +} diff --git a/modules/robot/modulerobot_mail.go b/modules/robot/modulerobot_mail.go new file mode 100644 index 000000000..c5d28e423 --- /dev/null +++ b/modules/robot/modulerobot_mail.go @@ -0,0 +1,76 @@ +package robot + +import ( + "errors" + "fmt" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//用户模块 机器人 +type ModuleRobot_Mail struct { + mails []*pb.DBMailData +} + +func (this *ModuleRobot_Mail) Init() (err error) { + + return +} + +//接收到消息 +func (this *ModuleRobot_Mail) Receive(robot IRobot, stype string, message proto.Message) (err error) { + switch stype { + case "getlist": + resp := message.(*pb.MailGetListResp) + this.mails = resp.Mails + break + case "getusermailattachment": + resp := message.(*pb.MailGetUserMailAttachmentResp) + for _, v := range this.mails { + if v.ObjId == resp.Mail.ObjId { + v.Reward = resp.Mail.Reward + break + } + } + break + } + return +} +func (this *ModuleRobot_Mail) OncePipeline(robot IRobot) (err error) { + var ( + errdata *pb.ErrorData + ) + if _, errdata = robot.SendMessage("mail", "getlist", &pb.MailGetListReq{}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + + return +} + +//机器人执行流 +func (this *ModuleRobot_Mail) DoPipeline(robot IRobot) (err error) { + var ( + errdata *pb.ErrorData + ) + for _, v := range this.mails { + if !v.Reward { + if _, errdata = robot.SendMessage("mail", "getusermailattachment", &pb.MailGetUserMailAttachmentReq{ + ObjID: v.ObjId, + }); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + break + } + } + return +} + +//做任务 +func (this *ModuleRobot_Mail) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { + + return +} diff --git a/modules/robot/modulerobot_storyline.go b/modules/robot/modulerobot_storyline.go new file mode 100644 index 000000000..e9d462741 --- /dev/null +++ b/modules/robot/modulerobot_storyline.go @@ -0,0 +1,54 @@ +package robot + +import ( + "errors" + "fmt" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//用户模块 机器人 +type ModuleRobot_Storyline struct { + info *pb.DBStoryline +} + +func (this *ModuleRobot_Storyline) Init() (err error) { + + return +} + +//接收到消息 +func (this *ModuleRobot_Storyline) Receive(robot IRobot, stype string, message proto.Message) (err error) { + switch stype { + case "info": + resp := message.(*pb.StorylineInfoResp) + this.info = resp.Info + break + } + return +} +func (this *ModuleRobot_Storyline) OncePipeline(robot IRobot) (err error) { + var ( + errdata *pb.ErrorData + ) + if _, errdata = robot.SendMessage("storyline", "info", &pb.StorylineInfoReq{}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + + return +} + +//机器人执行流 +func (this *ModuleRobot_Storyline) DoPipeline(robot IRobot) (err error) { + + return +} + +//做任务 +func (this *ModuleRobot_Storyline) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { + + return +} diff --git a/modules/robot/robot.go b/modules/robot/robot.go index d39311c7c..ce2f956ea 100644 --- a/modules/robot/robot.go +++ b/modules/robot/robot.go @@ -22,6 +22,7 @@ import ( type RobotStatistics struct { message string time int64 + reqsize int64 } type Robot struct { @@ -85,6 +86,11 @@ func (this *Robot) Init(addr string, client IClient) (err error) { this.modules[comm.ModuleSmithy] = new(ModuleRobot_Smithy) this.modules[comm.ModuleFriend] = new(ModuleRobot_Friend) this.modules[comm.ModulePasson] = new(ModuleRobot_Passon) + this.modules[comm.ModuleStoryLine] = new(ModuleRobot_Storyline) + this.modules[comm.ModuleDailytask] = new(ModuleRobot_Dailytask) + this.modules[comm.ModuleDragon] = new(ModuleRobot_Dragon) + this.modules[comm.ModuleIntegral] = new(ModuleRobot_Integral) + this.modules[comm.ModuleMail] = new(ModuleRobot_Mail) for _, v := range this.modules { v.Init() @@ -192,10 +198,10 @@ func (this *Robot) SendMessage(mtype, stype string, msg proto.Message) (resp pro log.Error("[机器人 Message]", log.Field{Key: "t", Value: time.Since(stime).Milliseconds()}, log.Field{Key: "Account", Value: this.account}, log.Field{Key: "message", Value: fmt.Sprintf("%s.%s", mtype, stype)}, log.Field{Key: "errdata", Value: errdata.String()}) } } - this.statistics = append(this.statistics, &RobotStatistics{ message: fmt.Sprintf("%s.%s", mtype, stype), time: time.Since(stime).Milliseconds(), + reqsize: int64(len(data.Value)), }) time.Sleep(time.Millisecond * time.Duration(50+rand.Int31n(300))) } else { diff --git a/modules/robot/statisticalcomp.go b/modules/robot/statisticalcomp.go index 952fb45bc..0a878cedb 100644 --- a/modules/robot/statisticalcomp.go +++ b/modules/robot/statisticalcomp.go @@ -81,10 +81,12 @@ func (this *statisticalComp) RobotFinishedTest(robot *Robot) { //输出报表 func (this *statisticalComp) OutReport() { var ( - messages map[string][]int64 = make(map[string][]int64) + messagestime map[string][]int64 = make(map[string][]int64) + requestsize map[string]int64 = make(map[string]int64) receive map[string]int32 = make(map[string]int32) receiveSize map[string]int64 = make(map[string]int64) totalmessage int32 + totalrequestSize int64 totalreceive int32 totalreceiveSize int64 ok bool @@ -93,10 +95,13 @@ func (this *statisticalComp) OutReport() { for _, datas := range this.robotdata { for _, v := range datas { totalmessage++ - if _, ok = messages[v.message]; !ok { - messages[v.message] = make([]int64, 0) + if _, ok = messagestime[v.message]; !ok { + messagestime[v.message] = make([]int64, 0) + } - messages[v.message] = append(messages[v.message], v.time) + messagestime[v.message] = append(messagestime[v.message], v.time) + requestsize[v.message] += v.reqsize + totalrequestSize += v.reqsize } } for k, v := range this.receiveMsg { @@ -114,19 +119,23 @@ func (this *statisticalComp) OutReport() { return } defer file.Close() - file.WriteString(fmt.Sprintf("机器人总数: %d\n", this.module.options.RobotTotalNum)) - file.WriteString(fmt.Sprintf("成功数量: %d\n", this.succclientNum)) - file.WriteString(fmt.Sprintf("失败数量: %d\n", this.failclientNum)) - file.WriteString(fmt.Sprintf("最大同时在线人数: %d\n", this.maxonlineNum)) - file.WriteString(fmt.Sprintf("压测执行时长: %.2f秒\n", this.end.Sub(this.start).Seconds())) + file.WriteString(fmt.Sprintf("机器人总数: %d\n", this.module.options.RobotTotalNum)) + file.WriteString(fmt.Sprintf("成功数量: %d\n", this.succclientNum)) + file.WriteString(fmt.Sprintf("失败数量: %d\n", this.failclientNum)) + file.WriteString(fmt.Sprintf("最大同时在线人数: %d\n", this.maxonlineNum)) file.WriteString(fmt.Sprintf("消息总请求数: %d\n", totalmessage)) - file.WriteString(fmt.Sprintf("消息总接收数: %d 接收消息总大小:%s\n", totalreceive, utils.FormatByesSize(totalreceiveSize))) + file.WriteString(fmt.Sprintf("消息总请求大小: %s\n", utils.FormatByesSize(totalrequestSize))) + file.WriteString(fmt.Sprintf("消息总接收数: %d\n", totalreceive)) + file.WriteString(fmt.Sprintf("消息总接收大小: %s\n", utils.FormatByesSize(totalreceiveSize))) + file.WriteString(fmt.Sprintf("压测执行时长: %.2f秒\n", this.end.Sub(this.start).Seconds())) file.WriteString(fmt.Sprintf("QPS: %.2f\n", float64(totalmessage)/this.end.Sub(this.start).Seconds())) file.WriteString("---消息压测详情----------------------------------------------------------------------------------------------------\n") - for message, data := range messages { + for message, data := range messagestime { sort.Slice(data, func(i, j int) bool { return data[i] < data[j] }) + reqsize := requestsize[message] + respsize := receiveSize[message] max := data[len(data)-1] min := data[0] sum := int64(0) @@ -140,11 +149,12 @@ func (this *statisticalComp) OutReport() { } else { median = float64(data[len(data)/2]) } - file.WriteString(fmt.Sprintf("消息名:%-20s 请求次数:%-5d 耗时最小:%-5dms 耗时最大:%-5dms 平均耗时:%-5.2fms 中位耗时:%-5.2fms \n", message, len(data), min, max, avg, median)) + file.WriteString(fmt.Sprintf("消息名:%-30s 请求次数:%-5d 请求数据:%-10s --%-2.2f%% 接收数据:%-10s --%-2.2f%% 耗时最小:%-5dms 耗时最大:%-5dms 平均耗时:%-5.2fms 中位耗时:%-5.2fms \n", message, len(data), utils.FormatByesSize(reqsize), 100*(float32(reqsize)/float32(totalrequestSize)), utils.FormatByesSize(respsize), 100*(float32(respsize)/float32(totalreceiveSize)), min, max, avg, median)) } - file.WriteString("---消息压测接收回包消息统计----------------------------------------------------------------------------------------------------\n") for k, v := range receive { - file.WriteString(fmt.Sprintf("消息名:%-20s 请求次数:%-5d 请求总大小:%s\n", k, v, utils.FormatByesSize(receiveSize[k]))) + if _, ok = messagestime[k]; !ok { + file.WriteString(fmt.Sprintf("消息名:%-30s 推送次数:%-5d 数据大小:%-5s --%-2.2f%% \n", k, v, utils.FormatByesSize(receiveSize[k]), 100*(float32(receiveSize[k])/float32(totalreceiveSize)))) + } } } diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index f752043dd..89523d242 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -28,6 +28,7 @@ type msghandle struct { // 组件参数 type CompOptions struct { + MaxTime int32 } func (this *CompOptions) LoadConfig(settings map[string]interface{}) (err error) { @@ -155,7 +156,7 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag reply.Reply = session.Polls() // log.Debugf("[Handle Api] t:%v m:%s uid:%s req:%v reply:%v", time.Since(stime), method, args.UserId, msg, reply) nt := time.Since(stime).Milliseconds() - if nt < 100 { + if this.options.MaxTime == 0 || nt < int64(this.options.MaxTime) { log.Debug("[Handle Api]", log.Field{Key: "t", Value: time.Since(stime).Milliseconds()}, log.Field{Key: "m", Value: method},