优化战斗代码
This commit is contained in:
parent
2aa07e9c66
commit
d3c73f0dd5
@ -1,9 +1,9 @@
|
|||||||
并发数: 1000
|
并发数: 2000
|
||||||
消息总请求数: 100000
|
消息总请求数: 200000
|
||||||
回合数: 4
|
回合数: 38
|
||||||
战报InfoSize: 3.36KB
|
战报InfoSize: 1.72KB
|
||||||
指令数: 214
|
指令数: 936
|
||||||
消息总请求大小: 26.87KB
|
消息总请求大小: 48.59KB
|
||||||
压测执行时长: 57.27秒
|
压测执行时长: 103.22秒
|
||||||
0-5ms------------------5-10ms -------------------10-20ms -------------------------20-50ms-------------------->50ms
|
0-5ms------------------5-10ms -------------------10-20ms -------------------------20-50ms-------------------->50ms
|
||||||
34859次 ------------------32413次 -------------------31566次 -------------------------1147 次-------------------->15 次
|
166409次 ------------------26867次 -------------------6120 次 -------------------------604 次-------------------->0 次
|
||||||
|
@ -13,13 +13,13 @@ import (
|
|||||||
"google.golang.org/protobuf/types/known/anypb"
|
"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{
|
msg := &pb.BattleRpcMessage{
|
||||||
Rid: 0,
|
Rid: 0,
|
||||||
Method: "Heartbeat",
|
Method: "Heartbeat",
|
||||||
}
|
}
|
||||||
data, _ := proto.Marshal(msg)
|
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{}
|
dialer := websocket.Dialer{}
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
if c.conn, _, err = dialer.DialContext(ctx, addr, nil); err != nil {
|
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 {
|
type client struct {
|
||||||
|
i int32
|
||||||
addr string
|
addr string
|
||||||
mgr IClientMgr
|
mgr IClientMgr
|
||||||
log log.ILogger
|
log log.ILogger
|
||||||
|
@ -19,8 +19,9 @@ type battleClientMgrComp struct {
|
|||||||
service core.IService
|
service core.IService
|
||||||
module *BattleTest
|
module *BattleTest
|
||||||
mutexs []sync.Mutex
|
mutexs []sync.Mutex
|
||||||
clinet *client
|
clinet []*client
|
||||||
i int
|
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) {
|
func (this *battleClientMgrComp) Start() (err error) {
|
||||||
err = this.ModuleCompBase.Start()
|
err = this.ModuleCompBase.Start()
|
||||||
|
this.clinet = make([]*client, this.options.ClientNum)
|
||||||
if this.options.OpenCheck {
|
if this.options.OpenCheck {
|
||||||
if this.clinet, err = newClient(this.options.BattleServerAddr, this, this.options.Log); err != nil {
|
for i := int32(0); i < (this.options.ClientNum); i++ {
|
||||||
return
|
if this.clinet[i], err = newClient(i, this.options.BattleServerAddr, this, this.options.Log); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -44,28 +48,33 @@ func (this *battleClientMgrComp) Start() (err error) {
|
|||||||
|
|
||||||
//关闭客户端连接对象
|
//关闭客户端连接对象
|
||||||
func (this *battleClientMgrComp) Shutdown(c *client) {
|
func (this *battleClientMgrComp) Shutdown(c *client) {
|
||||||
this.clinet = nil
|
this.clinet[c.i] = nil
|
||||||
log.Errorf("战斗校验服务被关闭!")
|
log.Errorf("战斗校验服务被关闭!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *battleClientMgrComp) reconnect() (err error) {
|
func (this *battleClientMgrComp) getclient() (_client *client, err error) {
|
||||||
if this.clinet != nil {
|
i := this.index % this.options.ClientNum
|
||||||
|
_client = this.clinet[i]
|
||||||
|
if _client != nil {
|
||||||
|
this.index++
|
||||||
return
|
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)
|
log.Errorln(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.clinet[i] = _client
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//校验战斗结果
|
//校验战斗结果
|
||||||
func (this *battleClientMgrComp) CheckBattle(ctx context.Context, req *pb.BattleReport) (reply *pb.BattleCheckResults, err error) {
|
func (this *battleClientMgrComp) CheckBattle(ctx context.Context, req *pb.BattleReport) (reply *pb.BattleCheckResults, err error) {
|
||||||
|
var client *client
|
||||||
reply = &pb.BattleCheckResults{}
|
reply = &pb.BattleCheckResults{}
|
||||||
if err = this.reconnect(); err != nil {
|
if client, err = this.getclient(); err != nil {
|
||||||
return
|
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)
|
log.Errorln(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
type (
|
type (
|
||||||
Options struct {
|
Options struct {
|
||||||
modules.Options
|
modules.Options
|
||||||
|
ClientNum int32
|
||||||
OpenCheck bool
|
OpenCheck bool
|
||||||
BattleServerAddr string
|
BattleServerAddr string
|
||||||
OutFilePath string
|
OutFilePath string
|
||||||
|
@ -65,10 +65,10 @@ func (this *pressuretestComp) Start() (err error) {
|
|||||||
this.round = int64(this.report.Round)
|
this.round = int64(this.report.Round)
|
||||||
datas, _ := proto.Marshal(this.report.Info)
|
datas, _ := proto.Marshal(this.report.Info)
|
||||||
this.battleinfosize = int64(len(datas))
|
this.battleinfosize = int64(len(datas))
|
||||||
// for _, v := range this.report.Outcmd {
|
for _, v := range this.report.Outcmd {
|
||||||
// datas, _ := proto.Marshal(v)
|
datas, _ := proto.Marshal(v)
|
||||||
// log.Debugf("指令:%s大小 %s:", v.Cmdtype, utils.FormatByesSize(int64(len(datas))))
|
log.Debugf("指令:%s大小 %s:", v.Cmdtype, utils.FormatByesSize(int64(len(datas))))
|
||||||
// }
|
}
|
||||||
this.cmdnum = int64(len(this.report.Outcmd))
|
this.cmdnum = int64(len(this.report.Outcmd))
|
||||||
this.workers = make([]*worker, this.module.options.Workers)
|
this.workers = make([]*worker, this.module.options.Workers)
|
||||||
this.start = time.Now()
|
this.start = time.Now()
|
||||||
|
@ -24,7 +24,7 @@ func (this *worker) Worker(wg *sync.WaitGroup) {
|
|||||||
)
|
)
|
||||||
locp:
|
locp:
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Millisecond * time.Duration(10+rand.Int31n(900)))
|
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(900)))
|
||||||
stime = time.Now()
|
stime = time.Now()
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
this.module.clientmgr.CheckBattle(ctx, this.report)
|
this.module.clientmgr.CheckBattle(ctx, this.report)
|
||||||
|
Loading…
Reference in New Issue
Block a user