From 509966784446a867681e077d37b6d0e43fa75846 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Fri, 9 Nov 2007 02:22:01 +0000 Subject: * Added some *VERY* experimental highly dodgy throttling of outbound packets to help alleviate clients borking during massive amounts of updates. Needs work. --- OpenSim/Region/ClientStack/ClientView.cs | 35 ++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index 0e35488..dfbf74c 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs @@ -87,6 +87,13 @@ namespace OpenSim.Region.ClientStack private int probesWithNoIngressPackets = 0; private int lastPacketsReceived = 0; + + private int throttleOutbound = 32768; // Number of bytes allowed to go out per second. (256kbps per client) + // TODO: Make this variable. Lower throttle on un-ack. Raise over time? + private int throttleSentPeriod = 0; // Number of bytes sent this period + + private Timer throttleTimer; + public ClientView(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, ClientManager clientManager, IScene scene, AssetCache assetCache, PacketServer packServer, AgentCircuitManager authenSessions) @@ -110,10 +117,14 @@ namespace OpenSim.Region.ClientStack PacketQueue = new BlockingQueue(); //this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache); - AckTimer = new Timer(500); + AckTimer = new Timer(750); AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); AckTimer.Start(); + throttleTimer = new Timer(1000); + throttleTimer.Elapsed += new ElapsedEventHandler(throttleTimer_Elapsed); + throttleTimer.Start(); + RegisterLocalPacketHandlers(); ClientThread = new Thread(new ThreadStart(AuthUser)); @@ -121,6 +132,11 @@ namespace OpenSim.Region.ClientStack ClientThread.Start(); } + void throttleTimer_Elapsed(object sender, ElapsedEventArgs e) + { + throttleSentPeriod = 0; + } + public LLUUID SessionId { get { return m_sessionId; } @@ -246,9 +262,20 @@ namespace OpenSim.Region.ClientStack } else { - //is a out going packet - DebugPacket("OUT", nextPacket.Packet); - ProcessOutPacket(nextPacket.Packet); + // Throw it back on the queue if it's going to cause us to flood the client + if (throttleSentPeriod > throttleOutbound) + { + PacketQueue.Enqueue(nextPacket); + Thread.Sleep(100); // Wait a little while, should prevent a CPU spike during high transmission periods + } + else + { + throttleSentPeriod += 768; // Average large packet size for now. + + //is a out going packet + DebugPacket("OUT", nextPacket.Packet); + ProcessOutPacket(nextPacket.Packet); + } } } } -- cgit v1.1