From 2dfe38a9275da8deb2cf0c598f0dd1f2ae997bda Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Tue, 26 Jan 2016 01:00:01 -0500 Subject: [PATCH] Cleanup, max message rate. --- main/network.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main/network.go b/main/network.go index 4c559a396..d72ae6584 100644 --- a/main/network.go +++ b/main/network.go @@ -124,15 +124,15 @@ func sendToAllConnectedClients(msg networkMessage) { } // Send non-queueable messages immediately, or discard if the client is in sleep mode. + if sleepFlag { + continue + } + netconn.numOverflows = 0 // Reset the overflow counter whenever the client is not sleeping so that we're not penalizing future sleepmodes. + if !msg.queueable { - if !sleepFlag { - netconn.Conn.Write(msg.msg) // Write immediately. - totalNetworkMessagesSent++ - } + netconn.Conn.Write(msg.msg) // Write immediately. + totalNetworkMessagesSent++ } else { - if !sleepFlag { - netconn.numOverflows = 0 // Reset the overflow counter whenever the client is not sleeping so that we're not penalizing future sleepmodes. - } // Queue the message if the message is "queueable". if len(netconn.messageQueue) >= maxUserMsgQueueSize { // Too many messages queued? Drop the oldest. log.Printf("%s:%d - message queue overflow.\n", netconn.Ip, netconn.Port) @@ -228,8 +228,8 @@ func messageQueueSender() { if stratuxClock.Since(lastQueueTimeChange) >= 5*time.Second { var pd float64 if averageSendableQueueSize > 0.0 && len(outSockets) > 0 { - averageSendableQueueSize = averageSendableQueueSize / float64(len(outSockets)) // It's a total, not an average, up until this point. - pd = math.Max(float64(1.0/2500.0), float64(1.0/(4.0*averageSendableQueueSize))) // Say 250ms is enough to get through the whole queue. + averageSendableQueueSize = averageSendableQueueSize / float64(len(outSockets)) // It's a total, not an average, up until this point. + pd = math.Max(float64(1.0/750.0), float64(1.0/(4.0*averageSendableQueueSize))) // Say 250ms is enough to get through the whole queue. } else { pd = float64(1.0 / 0.1) // 100ms. }