Changed dispacher's sleep strategy in order to reduce cpu load

This commit is contained in:
Andreas Neue 2016-07-26 22:10:50 +02:00
parent 9061079361
commit 0becd1d9ac
1 changed files with 6 additions and 4 deletions

View File

@ -41,6 +41,7 @@ type Server struct {
chUsers map[string]map[string]string chUsers map[string]map[string]string
chTopics map[string]string chTopics map[string]string
chModes map[string]map[string]bool chModes map[string]map[string]bool
config *conf.ConfigFile config *conf.ConfigFile
configPath string configPath string
@ -62,6 +63,7 @@ func NewServer(configPath, software, version string) *Server {
sv.delq = make(chan Client, 128) sv.delq = make(chan Client, 128)
sv.clients = make(map[string]Client) sv.clients = make(map[string]Client)
sv.chUsers = make(map[string]map[string]string) sv.chUsers = make(map[string]map[string]string)
sv.chTopics = make(map[string]string) sv.chTopics = make(map[string]string)
sv.chModes = make(map[string]map[string]bool) sv.chModes = make(map[string]map[string]bool)
@ -138,7 +140,6 @@ func (sv *Server) listenTls(laddr string) {
func (sv *Server) dispatcher() { func (sv *Server) dispatcher() {
for { for {
time.Sleep(1 * time.Microsecond)
sv.queueLen = float64(len(sv.queue)) sv.queueLen = float64(len(sv.queue))
select { select {
case msg := <-sv.queue: case msg := <-sv.queue:
@ -178,6 +179,7 @@ func (sv *Server) dispatcher() {
xlog.Info("Server has %d client(s)", len(sv.clients)) xlog.Info("Server has %d client(s)", len(sv.clients))
xlog.Debug("Goroutines running: %d", runtime.NumGoroutine()) xlog.Debug("Goroutines running: %d", runtime.NumGoroutine())
default: default:
time.Sleep(100 * time.Millisecond)
} }
} }
} }