From 0becd1d9ac134f0ef80bf19baeff038e7e85a893 Mon Sep 17 00:00:00 2001 From: Andreas Neue Date: Tue, 26 Jul 2016 22:10:50 +0200 Subject: [PATCH] Changed dispacher's sleep strategy in order to reduce cpu load --- server.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server.go b/server.go index 6c631ce..b8dc53c 100644 --- a/server.go +++ b/server.go @@ -38,9 +38,10 @@ type Server struct { clients map[string]Client - chUsers map[string]map[string]string - chTopics map[string]string - chModes map[string]map[string]bool + chUsers map[string]map[string]string + chTopics map[string]string + chModes map[string]map[string]bool + config *conf.ConfigFile configPath string @@ -62,6 +63,7 @@ func NewServer(configPath, software, version string) *Server { sv.delq = make(chan Client, 128) sv.clients = make(map[string]Client) + sv.chUsers = make(map[string]map[string]string) sv.chTopics = make(map[string]string) sv.chModes = make(map[string]map[string]bool) @@ -138,7 +140,6 @@ func (sv *Server) listenTls(laddr string) { func (sv *Server) dispatcher() { for { - time.Sleep(1 * time.Microsecond) sv.queueLen = float64(len(sv.queue)) select { case msg := <-sv.queue: @@ -178,6 +179,7 @@ func (sv *Server) dispatcher() { xlog.Info("Server has %d client(s)", len(sv.clients)) xlog.Debug("Goroutines running: %d", runtime.NumGoroutine()) default: + time.Sleep(100 * time.Millisecond) } } }