This commit is contained in:
zhouyuyan
2017-08-23 21:10:38 +08:00
parent 922a10fd66
commit e73776d670
6 changed files with 101 additions and 56 deletions

43
broker/dispatcher.go Normal file
View File

@@ -0,0 +1,43 @@
package broker
const (
WorkPoolNum = 1024
MaxUser = 1024 * 1024
MessagePoolNum = 1024
MessagePoolUser = MaxUser / MessagePoolNum
MessagePoolMessageNum = MaxUser / MessagePoolNum * 4
// MessageBoxNum = 256
// MessageBoxUserNum = MaxUser / MessageBoxNum
// MessageBoxMessageLength = MessageBoxUserNum
)
var (
MyDispatcher Dispatcher
)
type Dispatcher struct {
WorkerPool chan chan *Message
}
func init() {
workerPool = make(chan chan *Message, WorkPoolNum)
MyDispatcher = &Dispatcher{WorkerPool: workerPool}
}
func (d *Dispatcher) dispatch() {
for i := 0; i < MessagePoolNum; i++ {
go func(idx int) {
for {
select {
case msg := <-MSGPool[idx].Pop():
go func(msg *Message) {
msgChannel := <-d.WorkerPool
msgChannel <- msg
}(msg)
}
}
}(i)
}
}