Skip to content

Commit

Permalink
fix bug: #347
Browse files Browse the repository at this point in the history
  • Loading branch information
aceld committed Dec 6, 2024
1 parent d0ac08f commit 72f6801
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions znet/msghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func newMsgHandle() *MsgHandle {
// server
handle.WorkerPoolSize = zconf.GlobalObject.WorkerPoolSize
// One worker corresponds to one queue (一个worker对应一个queue)
handle.TaskQueue = make([]chan ziface.IRequest, handle.WorkerPoolSize)
handle.TaskQueue = make([]chan ziface.IRequest, TaskQueueLen)

// It is necessary to add the MsgHandle to the responsibility chain here, and it is the last link in the responsibility chain. After decoding in the MsgHandle, data distribution is done by router
// (此处必须把 msghandler 添加到责任链中,并且是责任链最后一环,在msghandler中进行解码后由router做数据分发)
Expand All @@ -105,6 +105,8 @@ func newMsgHandle() *MsgHandle {
// zinxRole: IClient
func newCliMsgHandle() *MsgHandle {
var freeWorkers map[uint32]struct{}
var extraFreeWorkers map[uint32]struct{}

if zconf.GlobalObject.WorkerMode == zconf.WorkerModeBind {
// Assign a workder to each link, avoid interactions when multiple links are processed by the same worker
// MaxWorkerTaskLen can also be reduced, for example, 50
Expand All @@ -117,6 +119,22 @@ func newCliMsgHandle() *MsgHandle {
}
}

TaskQueueLen := zconf.GlobalObject.WorkerPoolSize

if zconf.GlobalObject.WorkerMode == zconf.WorkerModeDynamicBind {
zlog.Ins().DebugF("WorkerMode = %s", zconf.WorkerModeDynamicBind)
freeWorkers = make(map[uint32]struct{}, zconf.GlobalObject.WorkerPoolSize)
for i := uint32(0); i < zconf.GlobalObject.WorkerPoolSize; i++ {
freeWorkers[i] = struct{}{}
}

extraFreeWorkers = make(map[uint32]struct{}, zconf.GlobalObject.MaxConn-int(zconf.GlobalObject.WorkerPoolSize))
for i := zconf.GlobalObject.WorkerPoolSize; i < uint32(zconf.GlobalObject.MaxConn); i++ {
extraFreeWorkers[i] = struct{}{}
}
TaskQueueLen = uint32(zconf.GlobalObject.MaxConn)
}

handle := &MsgHandle{
Apis: make(map[uint32]ziface.IRouter),
RouterSlices: NewRouterSlices(),
Expand All @@ -126,8 +144,9 @@ func newCliMsgHandle() *MsgHandle {

// client: Set worker pool size to 0 to turn off the worker pool in the client (客户端将协程池关闭)
handle.WorkerPoolSize = 0
TaskQueueLen = 0
// One worker corresponds to one queue (一个worker对应一个queue)
handle.TaskQueue = make([]chan ziface.IRequest, handle.WorkerPoolSize)
handle.TaskQueue = make([]chan ziface.IRequest, TaskQueueLen)

// It is necessary to add the MsgHandle to the responsibility chain here, and it is the last link in the responsibility chain. After decoding in the MsgHandle, data distribution is done by router
// (此处必须把 msghandler 添加到责任链中,并且是责任链最后一环,在msghandler中进行解码后由router做数据分发)
Expand Down

0 comments on commit 72f6801

Please sign in to comment.