diff --git a/bin/战斗服测试报告.txt b/bin/战斗服测试报告.txt index 69ab597b1..64bc37948 100644 --- a/bin/战斗服测试报告.txt +++ b/bin/战斗服测试报告.txt @@ -1,9 +1,9 @@ -并发数: 1000 -消息总请求数: 100000 -回合数: 4 -战报InfoSize: 3.36KB -指令数: 214 -消息总请求大小: 26.87KB -压测执行时长: 57.27秒 +并发数: 2000 +消息总请求数: 200000 +回合数: 38 +战报InfoSize: 1.72KB +指令数: 936 +消息总请求大小: 48.59KB +压测执行时长: 103.22秒 0-5ms------------------5-10ms -------------------10-20ms -------------------------20-50ms-------------------->50ms -34859次 ------------------32413次 -------------------31566次 -------------------------1147 次-------------------->15 次 +166409次 ------------------26867次 -------------------6120 次 -------------------------604 次-------------------->0 次 diff --git a/modules/battletest/battleclient.go b/modules/battletest/battleclient.go index a3704612e..06bc8f7bb 100644 --- a/modules/battletest/battleclient.go +++ b/modules/battletest/battleclient.go @@ -13,13 +13,13 @@ import ( "google.golang.org/protobuf/types/known/anypb" ) -func newClient(addr string, mgr IClientMgr, log log.ILogger) (c *client, err error) { +func newClient(i int32, addr string, mgr IClientMgr, log log.ILogger) (c *client, err error) { msg := &pb.BattleRpcMessage{ Rid: 0, Method: "Heartbeat", } data, _ := proto.Marshal(msg) - c = &client{addr: addr, mgr: mgr, log: log, seq: 1, state: 1, pending: make(map[uint64]*MessageCall), heartbeatpack: data} + c = &client{i: i, addr: addr, mgr: mgr, log: log, seq: 1, state: 1, pending: make(map[uint64]*MessageCall), heartbeatpack: data} dialer := websocket.Dialer{} ctx, _ := context.WithTimeout(context.Background(), time.Second*5) if c.conn, _, err = dialer.DialContext(ctx, addr, nil); err != nil { @@ -31,6 +31,7 @@ func newClient(addr string, mgr IClientMgr, log log.ILogger) (c *client, err err } type client struct { + i int32 addr string mgr IClientMgr log log.ILogger diff --git a/modules/battletest/battleclientmgr.go b/modules/battletest/battleclientmgr.go index 19a684d7d..8ec5586fc 100644 --- a/modules/battletest/battleclientmgr.go +++ b/modules/battletest/battleclientmgr.go @@ -19,8 +19,9 @@ type battleClientMgrComp struct { service core.IService module *BattleTest mutexs []sync.Mutex - clinet *client - i int + clinet []*client + lock sync.Mutex + index int32 } //组件初始化接口 @@ -34,9 +35,12 @@ func (this *battleClientMgrComp) Init(service core.IService, module core.IModule func (this *battleClientMgrComp) Start() (err error) { err = this.ModuleCompBase.Start() + this.clinet = make([]*client, this.options.ClientNum) if this.options.OpenCheck { - if this.clinet, err = newClient(this.options.BattleServerAddr, this, this.options.Log); err != nil { - return + for i := int32(0); i < (this.options.ClientNum); i++ { + if this.clinet[i], err = newClient(i, this.options.BattleServerAddr, this, this.options.Log); err != nil { + return + } } } return @@ -44,28 +48,33 @@ func (this *battleClientMgrComp) Start() (err error) { //关闭客户端连接对象 func (this *battleClientMgrComp) Shutdown(c *client) { - this.clinet = nil + this.clinet[c.i] = nil log.Errorf("战斗校验服务被关闭!") } -func (this *battleClientMgrComp) reconnect() (err error) { - if this.clinet != nil { +func (this *battleClientMgrComp) getclient() (_client *client, err error) { + i := this.index % this.options.ClientNum + _client = this.clinet[i] + if _client != nil { + this.index++ return } - if this.clinet, err = newClient(this.options.BattleServerAddr, this, this.options.Log); err != nil { + if _client, err = newClient(i, this.options.BattleServerAddr, this, this.options.Log); err != nil { log.Errorln(err) return } + this.clinet[i] = _client return } //校验战斗结果 func (this *battleClientMgrComp) CheckBattle(ctx context.Context, req *pb.BattleReport) (reply *pb.BattleCheckResults, err error) { + var client *client reply = &pb.BattleCheckResults{} - if err = this.reconnect(); err != nil { + if client, err = this.getclient(); err != nil { return } - if err = this.clinet.callBattle(ctx, "Check", req, reply); err != nil { + if err = client.callBattle(ctx, "Check", req, reply); err != nil { log.Errorln(err) } return diff --git a/modules/battletest/options.go b/modules/battletest/options.go index 38bd31bd1..1109b136b 100644 --- a/modules/battletest/options.go +++ b/modules/battletest/options.go @@ -8,6 +8,7 @@ import ( type ( Options struct { modules.Options + ClientNum int32 OpenCheck bool BattleServerAddr string OutFilePath string diff --git a/modules/battletest/pressuretest.go b/modules/battletest/pressuretest.go index 2bb05c3b5..637620cfc 100644 --- a/modules/battletest/pressuretest.go +++ b/modules/battletest/pressuretest.go @@ -65,10 +65,10 @@ func (this *pressuretestComp) Start() (err error) { this.round = int64(this.report.Round) datas, _ := proto.Marshal(this.report.Info) this.battleinfosize = int64(len(datas)) - // for _, v := range this.report.Outcmd { - // datas, _ := proto.Marshal(v) - // log.Debugf("指令:%s大小 %s:", v.Cmdtype, utils.FormatByesSize(int64(len(datas)))) - // } + for _, v := range this.report.Outcmd { + datas, _ := proto.Marshal(v) + log.Debugf("指令:%s大小 %s:", v.Cmdtype, utils.FormatByesSize(int64(len(datas)))) + } this.cmdnum = int64(len(this.report.Outcmd)) this.workers = make([]*worker, this.module.options.Workers) this.start = time.Now() diff --git a/modules/battletest/worker.go b/modules/battletest/worker.go index ba56df7e9..572f9ac24 100644 --- a/modules/battletest/worker.go +++ b/modules/battletest/worker.go @@ -24,7 +24,7 @@ func (this *worker) Worker(wg *sync.WaitGroup) { ) locp: for { - time.Sleep(time.Millisecond * time.Duration(10+rand.Int31n(900))) + time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(900))) stime = time.Now() ctx, _ := context.WithTimeout(context.Background(), time.Second*5) this.module.clientmgr.CheckBattle(ctx, this.report)