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
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)
}
}
}