* now the throttle timer is stopped whilst processing Queue so that it won't fire twice

* started to refactored throttling method
* some code convention refactorings
afrisby
lbsa71 2007-12-06 14:08:22 +00:00
parent 44caa7ae8e
commit 395637acdd
3 changed files with 304 additions and 268 deletions

View File

@ -776,8 +776,13 @@ namespace OpenSim.Framework.Communications.Cache
im.Header.Reliable = false;
im.ImageID.Packet = (ushort) (req.PacketCounter);
im.ImageID.ID = req.ImageInfo.FullID;
int size = req.ImageInfo.Data.Length - 600 - (1000*(req.PacketCounter - 1));
if (size > 1000) size = 1000;
if (size > 1000)
{
size = 1000;
}
//Console.WriteLine("length= {0} counter= {1} size= {2}",req.ImageInfo.Data.Length, req.PacketCounter, size);
im.ImageData.Data = new byte[size];
Array.Copy(req.ImageInfo.Data, 600 + (1000*(req.PacketCounter - 1)), im.ImageData.Data, 0, size);

View File

@ -91,62 +91,62 @@ namespace OpenSim.Region.ClientStack
protected AgentCircuitManager m_authenticateSessionsHandler;
private Encoding enc = Encoding.ASCII;
// Dead client detection vars
private Timer clientPingTimer;
private int packetsReceived = 0;
private int probesWithNoIngressPackets = 0;
private int lastPacketsReceived = 0;
private Timer m_clientPingTimer;
private int m_packetsReceived = 0;
private int m_probesWithNoIngressPackets = 0;
private int m_lastPacketsReceived = 0;
// 1536000
private int throttleOutboundMax = 1536000; // Number of bytes allowed to go out per second. (256kbps per client)
private int m_throttleOutboundMax = 1536000; // 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 bytesSent = 0; // Number of bytes sent this period
private int m_bytesSent = 0; // Number of bytes sent this period
private int throttleOutbound = 162144; // Number of bytes allowed to go out per second. (256kbps per client)
private int m_throttleOutbound = 162144; // Number of bytes allowed to go out per second. (256kbps per client)
// TODO: Make this variable. Lower throttle on un-ack. Raise over time
// All throttle times and number of bytes are calculated by dividing by this value
// This value also determines how many times per throttletimems the timer will run
// If throttleimems is 1000 ms, then the timer will fire every 1000/7 milliseconds
private int throttleTimeDivisor = 7;
private int m_throttleTimeDivisor = 7;
private int throttletimems = 1000;
private int m_throttletimems = 1000;
// Maximum -per type- throttle
private int ResendthrottleMAX = 100000;
private int LandthrottleMax = 100000;
private int WindthrottleMax = 100000;
private int CloudthrottleMax = 100000;
private int TaskthrottleMax = 800000;
private int AssetthrottleMax = 800000;
private int TexturethrottleMax = 800000;
private int m_resendthrottleMAX = 100000;
private int m_landthrottleMax = 100000;
private int m_windthrottleMax = 100000;
private int m_cloudthrottleMax = 100000;
private int m_taskthrottleMax = 800000;
private int m_assetthrottleMax = 800000;
private int m_texturethrottleMax = 800000;
// Minimum -per type- throttle
private int ResendthrottleMin = 5000; // setting resendmin to 0 results in mostly dropped packets
private int LandthrottleMin = 1000;
private int WindthrottleMin = 1000;
private int CloudthrottleMin = 1000;
private int TaskthrottleMin = 1000;
private int AssetthrottleMin = 1000;
private int TexturethrottleMin = 1000;
private int m_resendthrottleMin = 5000; // setting resendmin to 0 results in mostly dropped packets
private int m_landthrottleMin = 1000;
private int m_windthrottleMin = 1000;
private int m_cloudthrottleMin = 1000;
private int m_taskthrottleMin = 1000;
private int m_assetthrottleMin = 1000;
private int m_texturethrottleMin = 1000;
// Sim default per-client settings.
private int ResendthrottleOutbound = 50000;
private int ResendBytesSent = 0;
private int LandthrottleOutbound = 100000;
private int LandBytesSent = 0;
private int WindthrottleOutbound = 10000;
private int WindBytesSent = 0;
private int CloudthrottleOutbound = 5000;
private int CloudBytesSent = 0;
private int TaskthrottleOutbound = 100000;
private int TaskBytesSent = 0;
private int AssetthrottleOutbound = 80000;
private int AssetBytesSent = 0;
private int TexturethrottleOutbound = 100000;
private int TextureBytesSent = 0;
private int m_resendthrottleOutbound = 50000;
private int m_resendBytesSent = 0;
private int m_landthrottleOutbound = 100000;
private int m_landBytesSent = 0;
private int m_windthrottleOutbound = 10000;
private int m_windBytesSent = 0;
private int m_cloudthrottleOutbound = 5000;
private int m_cloudBytesSent = 0;
private int m_taskthrottleOutbound = 100000;
private int m_taskBytesSent = 0;
private int m_assetthrottleOutbound = 80000;
private int m_assetBytesSent = 0;
private int m_texturethrottleOutbound = 100000;
private int m_textureBytesSent = 0;
private Timer throttleTimer;
private Timer m_throttleTimer;
public ClientView(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, ClientManager clientManager,
IScene scene, AssetCache assetCache, PacketServer packServer,
@ -174,17 +174,17 @@ namespace OpenSim.Region.ClientStack
// in it to process. it's an on-purpose threadlock though because
// without it, the clientloop will suck up all sim resources.
PacketQueue = new BlockingQueue<QueItem>();
m_packetQueue = new BlockingQueue<QueItem>();
IncomingPacketQueue = new Queue<QueItem>();
OutgoingPacketQueue = new Queue<QueItem>();
ResendOutgoingPacketQueue = new Queue<QueItem>();
LandOutgoingPacketQueue = new Queue<QueItem>();
WindOutgoingPacketQueue = new Queue<QueItem>();
CloudOutgoingPacketQueue = new Queue<QueItem>();
TaskOutgoingPacketQueue = new Queue<QueItem>();
TextureOutgoingPacketQueue = new Queue<QueItem>();
AssetOutgoingPacketQueue = new Queue<QueItem>();
m_incomingPacketQueue = new Queue<QueItem>();
m_outgoingPacketQueue = new Queue<QueItem>();
m_resendOutgoingPacketQueue = new Queue<QueItem>();
m_landOutgoingPacketQueue = new Queue<QueItem>();
m_windOutgoingPacketQueue = new Queue<QueItem>();
m_cloudOutgoingPacketQueue = new Queue<QueItem>();
m_taskOutgoingPacketQueue = new Queue<QueItem>();
m_textureOutgoingPacketQueue = new Queue<QueItem>();
m_assetOutgoingPacketQueue = new Queue<QueItem>();
//this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
@ -192,9 +192,9 @@ namespace OpenSim.Region.ClientStack
AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
AckTimer.Start();
throttleTimer = new Timer((int)(throttletimems/throttleTimeDivisor));
throttleTimer.Elapsed += new ElapsedEventHandler(throttleTimer_Elapsed);
throttleTimer.Start();
m_throttleTimer = new Timer((int)(m_throttletimems/m_throttleTimeDivisor));
m_throttleTimer.Elapsed += throttleTimer_Elapsed;
m_throttleTimer.Start();
RegisterLocalPacketHandlers();
@ -205,14 +205,24 @@ namespace OpenSim.Region.ClientStack
void throttleTimer_Elapsed(object sender, ElapsedEventArgs e)
{
bytesSent = 0;
ResendBytesSent = 0;
LandBytesSent = 0;
WindBytesSent = 0;
CloudBytesSent = 0;
TaskBytesSent = 0;
AssetBytesSent = 0;
TextureBytesSent = 0;
// We need to stop the timer so that another timer event won't cause queue races.
m_throttleTimer.Stop();
ProcessThrottleQueues();
m_throttleTimer.Start();
}
private void ProcessThrottleQueues()
{
m_bytesSent = 0;
m_resendBytesSent = 0;
m_landBytesSent = 0;
m_windBytesSent = 0;
m_cloudBytesSent = 0;
m_taskBytesSent = 0;
m_assetBytesSent = 0;
m_textureBytesSent = 0;
// I was considering this.. Will an event fire if the thread it's on is blocked?
@ -225,76 +235,96 @@ namespace OpenSim.Region.ClientStack
// We're going to dequeue all of the saved up packets until
// we've hit the throttle limit or there's no more packets to send
while ((bytesSent <= ((int)(throttleOutbound/throttleTimeDivisor)) &&
(ResendOutgoingPacketQueue.Count > 0 ||
LandOutgoingPacketQueue.Count > 0 ||
WindOutgoingPacketQueue.Count > 0 ||
CloudOutgoingPacketQueue.Count > 0 ||
TaskOutgoingPacketQueue.Count > 0 ||
AssetOutgoingPacketQueue.Count > 0 ||
TextureOutgoingPacketQueue.Count > 0)) && throttleLoops <= MaxThrottleLoops)
while (TimeToDequeue( m_bytesSent, m_throttleOutbound ) &&
(m_resendOutgoingPacketQueue.Count > 0 ||
m_landOutgoingPacketQueue.Count > 0 ||
m_windOutgoingPacketQueue.Count > 0 ||
m_cloudOutgoingPacketQueue.Count > 0 ||
m_taskOutgoingPacketQueue.Count > 0 ||
m_assetOutgoingPacketQueue.Count > 0 ||
m_textureOutgoingPacketQueue.Count > 0) && ( throttleLoops <= MaxThrottleLoops))
{
throttleLoops++;
//Now comes the fun part.. we dump all our elements into PacketQueue that we've saved up.
if (ResendBytesSent <= ((int)(ResendthrottleOutbound/throttleTimeDivisor)) && ResendOutgoingPacketQueue.Count > 0)
{
QueItem qpack = ResendOutgoingPacketQueue.Dequeue();
PacketQueue.Enqueue(qpack);
bytesSent += qpack.Packet.ToBytes().Length;
ResendBytesSent += qpack.Packet.ToBytes().Length;
if (TimeToDequeue(m_resendBytesSent, m_resendthrottleOutbound))
{
m_resendBytesSent += ProcessQueue(m_resendOutgoingPacketQueue);
}
if (LandBytesSent <= ((int)(LandthrottleOutbound/throttleTimeDivisor)) && LandOutgoingPacketQueue.Count > 0)
{
QueItem qpack = LandOutgoingPacketQueue.Dequeue();
PacketQueue.Enqueue(qpack);
bytesSent += qpack.Packet.ToBytes().Length;
LandBytesSent += qpack.Packet.ToBytes().Length;
if (TimeToDequeue(m_landBytesSent, m_landthrottleOutbound))
{
m_landBytesSent += ProcessQueue(m_landOutgoingPacketQueue);
}
if (WindBytesSent <= ((int)(WindthrottleOutbound/throttleTimeDivisor)) && WindOutgoingPacketQueue.Count > 0)
{
QueItem qpack = WindOutgoingPacketQueue.Dequeue();
PacketQueue.Enqueue(qpack);
bytesSent += qpack.Packet.ToBytes().Length;
WindBytesSent += qpack.Packet.ToBytes().Length;
// -- TODO: Well, do the same for the rest of them
if (m_windBytesSent <= ((int)(m_windthrottleOutbound/m_throttleTimeDivisor)) && m_windOutgoingPacketQueue.Count > 0)
{
QueItem qpack = m_windOutgoingPacketQueue.Dequeue();
m_packetQueue.Enqueue(qpack);
m_bytesSent += qpack.Packet.ToBytes().Length;
m_windBytesSent += qpack.Packet.ToBytes().Length;
}
if (CloudBytesSent <= ((int)(CloudthrottleOutbound/throttleTimeDivisor)) && CloudOutgoingPacketQueue.Count > 0)
if (m_cloudBytesSent <= ((int)(m_cloudthrottleOutbound/m_throttleTimeDivisor)) && m_cloudOutgoingPacketQueue.Count > 0)
{
QueItem qpack = CloudOutgoingPacketQueue.Dequeue();
QueItem qpack = m_cloudOutgoingPacketQueue.Dequeue();
PacketQueue.Enqueue(qpack);
bytesSent += qpack.Packet.ToBytes().Length;
CloudBytesSent += qpack.Packet.ToBytes().Length;
m_packetQueue.Enqueue(qpack);
m_bytesSent += qpack.Packet.ToBytes().Length;
m_cloudBytesSent += qpack.Packet.ToBytes().Length;
}
if (TaskBytesSent <= ((int)(TaskthrottleOutbound/throttleTimeDivisor)) && TaskOutgoingPacketQueue.Count > 0)
if (m_taskBytesSent <= ((int)(m_taskthrottleOutbound/m_throttleTimeDivisor)) && m_taskOutgoingPacketQueue.Count > 0)
{
QueItem qpack = TaskOutgoingPacketQueue.Dequeue();
QueItem qpack = m_taskOutgoingPacketQueue.Dequeue();
PacketQueue.Enqueue(qpack);
bytesSent += qpack.Packet.ToBytes().Length;
TaskBytesSent += qpack.Packet.ToBytes().Length;
m_packetQueue.Enqueue(qpack);
m_bytesSent += qpack.Packet.ToBytes().Length;
m_taskBytesSent += qpack.Packet.ToBytes().Length;
}
if (TextureBytesSent <= ((int)(TexturethrottleOutbound/throttleTimeDivisor)) && TextureOutgoingPacketQueue.Count > 0)
if (m_textureBytesSent <= ((int)(m_texturethrottleOutbound/m_throttleTimeDivisor)) && m_textureOutgoingPacketQueue.Count > 0)
{
QueItem qpack = TextureOutgoingPacketQueue.Dequeue();
QueItem qpack = m_textureOutgoingPacketQueue.Dequeue();
PacketQueue.Enqueue(qpack);
bytesSent += qpack.Packet.ToBytes().Length;
TextureBytesSent += qpack.Packet.ToBytes().Length;
m_packetQueue.Enqueue(qpack);
m_bytesSent += qpack.Packet.ToBytes().Length;
m_textureBytesSent += qpack.Packet.ToBytes().Length;
}
if (AssetBytesSent <= ((int)(AssetthrottleOutbound/throttleTimeDivisor)) && AssetOutgoingPacketQueue.Count > 0)
if (m_assetBytesSent <= ((int)(m_assetthrottleOutbound/m_throttleTimeDivisor)) && m_assetOutgoingPacketQueue.Count > 0)
{
QueItem qpack = AssetOutgoingPacketQueue.Dequeue();
QueItem qpack = m_assetOutgoingPacketQueue.Dequeue();
PacketQueue.Enqueue(qpack);
bytesSent += qpack.Packet.ToBytes().Length;
AssetBytesSent += qpack.Packet.ToBytes().Length;
m_packetQueue.Enqueue(qpack);
m_bytesSent += qpack.Packet.ToBytes().Length;
m_assetBytesSent += qpack.Packet.ToBytes().Length;
}
}
}
private int ProcessQueue(Queue<QueItem> queue)
{
if (queue.Count > 0)
{
QueItem qpack = queue.Dequeue();
m_packetQueue.Enqueue(qpack);
int packLength = qpack.Packet.ToBytes().Length;
m_bytesSent += packLength;
return packLength;
}
return 0;
}
private bool TimeToDequeue(int bytesSent, int outboundThrottle)
{
return bytesSent <= ((int)(outboundThrottle / m_throttleTimeDivisor));
}
public LLUUID SessionId
@ -311,7 +341,7 @@ namespace OpenSim.Region.ClientStack
public void Close()
{
clientPingTimer.Stop();
m_clientPingTimer.Stop();
m_scene.RemoveClient(AgentId);
@ -333,7 +363,7 @@ namespace OpenSim.Region.ClientStack
}
public void Stop()
{
clientPingTimer.Stop();
m_clientPingTimer.Stop();
libsecondlife.Packets.DisableSimulatorPacket disable = new libsecondlife.Packets.DisableSimulatorPacket();
OutPacket(disable, ThrottleOutPacketType.Task);
@ -434,7 +464,7 @@ namespace OpenSim.Region.ClientStack
MainLog.Instance.Verbose("CLIENT", "Entered loop");
while (true)
{
QueItem nextPacket = PacketQueue.Dequeue();
QueItem nextPacket = m_packetQueue.Dequeue();
if (nextPacket.Incoming)
{
queuedLast = false;
@ -442,7 +472,7 @@ namespace OpenSim.Region.ClientStack
//is a incoming packet
if (nextPacket.Packet.Type != PacketType.AgentUpdate)
{
packetsReceived++;
m_packetsReceived++;
}
DebugPacket("IN", nextPacket.Packet);
ProcessInPacket(nextPacket.Packet);
@ -450,9 +480,9 @@ namespace OpenSim.Region.ClientStack
else
{
// Throw it back on the queue if it's going to cause us to flood the client
if (bytesSent > throttleOutboundMax)
if (m_bytesSent > m_throttleOutboundMax)
{
PacketQueue.Enqueue(nextPacket);
m_packetQueue.Enqueue(nextPacket);
MainLog.Instance.Verbose("THROTTLE", "Client over throttle limit, requeuing packet");
if (queuedLast)
@ -471,7 +501,7 @@ namespace OpenSim.Region.ClientStack
//Don't throttle AvatarPickerReplies!, they return a null .ToBytes()!
if (nextPacket.Packet.Type != PacketType.AvatarPickerReply)
bytesSent += nextPacket.Packet.ToBytes().Length;
m_bytesSent += nextPacket.Packet.ToBytes().Length;
//is a out going packet
@ -487,10 +517,10 @@ namespace OpenSim.Region.ClientStack
protected void CheckClientConnectivity(object sender, ElapsedEventArgs e)
{
if (packetsReceived == lastPacketsReceived)
if (m_packetsReceived == m_lastPacketsReceived)
{
probesWithNoIngressPackets++;
if (probesWithNoIngressPackets > 30)
m_probesWithNoIngressPackets++;
if (m_probesWithNoIngressPackets > 30)
{
if (OnConnectionClosed != null)
{
@ -506,8 +536,8 @@ namespace OpenSim.Region.ClientStack
else
{
// Something received in the meantime - we can reset the counters
probesWithNoIngressPackets = 0;
lastPacketsReceived = packetsReceived;
m_probesWithNoIngressPackets = 0;
m_lastPacketsReceived = m_packetsReceived;
}
}
@ -515,9 +545,9 @@ namespace OpenSim.Region.ClientStack
protected virtual void InitNewClient()
{
clientPingTimer = new Timer(5000);
clientPingTimer.Elapsed += new ElapsedEventHandler(CheckClientConnectivity);
clientPingTimer.Enabled = true;
m_clientPingTimer = new Timer(5000);
m_clientPingTimer.Elapsed += new ElapsedEventHandler(CheckClientConnectivity);
m_clientPingTimer.Enabled = true;
MainLog.Instance.Verbose("CLIENT", "Adding viewer agent to scene");
m_scene.AddNewClient(this, true);
@ -2203,20 +2233,20 @@ namespace OpenSim.Region.ClientStack
}
// Previously ClientView.PacketQueue
protected BlockingQueue<QueItem> PacketQueue;
protected BlockingQueue<QueItem> m_packetQueue;
protected Queue<QueItem> IncomingPacketQueue;
protected Queue<QueItem> OutgoingPacketQueue;
protected Queue<QueItem> ResendOutgoingPacketQueue;
protected Queue<QueItem> LandOutgoingPacketQueue;
protected Queue<QueItem> WindOutgoingPacketQueue;
protected Queue<QueItem> CloudOutgoingPacketQueue;
protected Queue<QueItem> TaskOutgoingPacketQueue;
protected Queue<QueItem> TextureOutgoingPacketQueue;
protected Queue<QueItem> AssetOutgoingPacketQueue;
protected Queue<QueItem> m_incomingPacketQueue;
protected Queue<QueItem> m_outgoingPacketQueue;
protected Queue<QueItem> m_resendOutgoingPacketQueue;
protected Queue<QueItem> m_landOutgoingPacketQueue;
protected Queue<QueItem> m_windOutgoingPacketQueue;
protected Queue<QueItem> m_cloudOutgoingPacketQueue;
protected Queue<QueItem> m_taskOutgoingPacketQueue;
protected Queue<QueItem> m_textureOutgoingPacketQueue;
protected Queue<QueItem> m_assetOutgoingPacketQueue;
protected Dictionary<uint, uint> PendingAcks = new Dictionary<uint, uint>();
protected Dictionary<uint, Packet> NeedAck = new Dictionary<uint, Packet>();
protected Dictionary<uint, uint> m_pendingAcks = new Dictionary<uint, uint>();
protected Dictionary<uint, Packet> m_needAck = new Dictionary<uint, Packet>();
protected Timer AckTimer;
protected uint Sequence = 0;
@ -2258,13 +2288,13 @@ namespace OpenSim.Region.ClientStack
protected void AddAck(Packet Pack)
{
lock (NeedAck)
lock (m_needAck)
{
if (!NeedAck.ContainsKey(Pack.Header.Sequence))
if (!m_needAck.ContainsKey(Pack.Header.Sequence))
{
try
{
NeedAck.Add(Pack.Header.Sequence, Pack);
m_needAck.Add(Pack.Header.Sequence, Pack);
}
catch (Exception e) // HACKY
{
@ -2278,7 +2308,7 @@ namespace OpenSim.Region.ClientStack
else
{
// Client.Log("Attempted to add a duplicate sequence number (" +
// packet.Header.Sequence + ") to the NeedAck dictionary for packet type " +
// packet.Header.Sequence + ") to the m_needAck dictionary for packet type " +
// packet.Type.ToString(), Helpers.LogLevel.Warning);
}
}
@ -2287,21 +2317,21 @@ namespace OpenSim.Region.ClientStack
protected virtual void SetPendingAcks(ref Packet Pack)
{
// Append any ACKs that need to be sent out to this packet
lock (PendingAcks)
lock (m_pendingAcks)
{
// TODO: If we are over MAX_APPENDED_ACKS we should drain off some of these
if (PendingAcks.Count > 0 && PendingAcks.Count < MAX_APPENDED_ACKS)
if (m_pendingAcks.Count > 0 && m_pendingAcks.Count < MAX_APPENDED_ACKS)
{
Pack.Header.AckList = new uint[PendingAcks.Count];
Pack.Header.AckList = new uint[m_pendingAcks.Count];
int i = 0;
foreach (uint ack in PendingAcks.Values)
foreach (uint ack in m_pendingAcks.Values)
{
Pack.Header.AckList[i] = ack;
i++;
}
PendingAcks.Clear();
m_pendingAcks.Clear();
Pack.Header.AppendedAcks = true;
}
}
@ -2357,11 +2387,11 @@ namespace OpenSim.Region.ClientStack
// Handle appended ACKs
if (NewPack.Header.AppendedAcks)
{
lock (NeedAck)
lock (m_needAck)
{
foreach (uint ack in NewPack.Header.AckList)
{
NeedAck.Remove(ack);
m_needAck.Remove(ack);
}
}
}
@ -2371,11 +2401,11 @@ namespace OpenSim.Region.ClientStack
{
PacketAckPacket ackPacket = (PacketAckPacket) NewPack;
lock (NeedAck)
lock (m_needAck)
{
foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
{
NeedAck.Remove(block.ID);
m_needAck.Remove(block.ID);
}
}
}
@ -2392,7 +2422,7 @@ namespace OpenSim.Region.ClientStack
QueItem item = new QueItem();
item.Packet = NewPack;
item.Incoming = true;
PacketQueue.Enqueue(item);
m_packetQueue.Enqueue(item);
}
}
@ -2404,11 +2434,11 @@ namespace OpenSim.Region.ClientStack
// wait for the timer to fire to put things into the
// output queue
if((q.Count == 0) && (TypeBytesSent <= ((int)(Throttle / throttleTimeDivisor))))
if((q.Count == 0) && (TypeBytesSent <= ((int)(Throttle / m_throttleTimeDivisor))))
{
bytesSent += item.Packet.ToBytes().Length;
m_bytesSent += item.Packet.ToBytes().Length;
TypeBytesSent += item.Packet.ToBytes().Length;
PacketQueue.Enqueue(item);
m_packetQueue.Enqueue(item);
}
else
{
@ -2428,34 +2458,34 @@ namespace OpenSim.Region.ClientStack
switch (throttlePacketType)
{
case ThrottleOutPacketType.Resend:
ThrottleCheck(ref ResendBytesSent, ResendthrottleOutbound, ref ResendOutgoingPacketQueue, item);
ThrottleCheck(ref m_resendBytesSent, m_resendthrottleOutbound, ref m_resendOutgoingPacketQueue, item);
break;
case ThrottleOutPacketType.Texture:
ThrottleCheck(ref TextureBytesSent, TexturethrottleOutbound, ref TextureOutgoingPacketQueue, item);
ThrottleCheck(ref m_textureBytesSent, m_texturethrottleOutbound, ref m_textureOutgoingPacketQueue, item);
break;
case ThrottleOutPacketType.Task:
ThrottleCheck(ref TaskBytesSent, TaskthrottleOutbound, ref TaskOutgoingPacketQueue, item);
ThrottleCheck(ref m_taskBytesSent, m_taskthrottleOutbound, ref m_taskOutgoingPacketQueue, item);
break;
case ThrottleOutPacketType.Land:
ThrottleCheck(ref LandBytesSent, LandthrottleOutbound, ref LandOutgoingPacketQueue, item);
ThrottleCheck(ref m_landBytesSent, m_landthrottleOutbound, ref m_landOutgoingPacketQueue, item);
break;
case ThrottleOutPacketType.Asset:
ThrottleCheck(ref AssetBytesSent, AssetthrottleOutbound, ref AssetOutgoingPacketQueue, item);
ThrottleCheck(ref m_assetBytesSent, m_assetthrottleOutbound, ref m_assetOutgoingPacketQueue, item);
break;
case ThrottleOutPacketType.Cloud:
ThrottleCheck(ref CloudBytesSent, CloudthrottleOutbound, ref CloudOutgoingPacketQueue, item);
ThrottleCheck(ref m_cloudBytesSent, m_cloudthrottleOutbound, ref m_cloudOutgoingPacketQueue, item);
break;
case ThrottleOutPacketType.Wind:
ThrottleCheck(ref WindBytesSent, WindthrottleOutbound, ref WindOutgoingPacketQueue, item);
ThrottleCheck(ref m_windBytesSent, m_windthrottleOutbound, ref m_windOutgoingPacketQueue, item);
break;
default:
// Acknowledgements and other such stuff should go directly to the blocking Queue
// Throttling them may and likely 'will' be problematic
PacketQueue.Enqueue(item);
m_packetQueue.Enqueue(item);
break;
}
//OutgoingPacketQueue.Enqueue(item);
//m_outgoingPacketQueue.Enqueue(item);
}
# region Low Level Packet Methods
@ -2475,10 +2505,10 @@ namespace OpenSim.Region.ClientStack
/*
if (Pack.Header.Reliable)
{
lock (PendingAcks)
lock (m_pendingAcks)
{
uint sequence = (uint)Pack.Header.Sequence;
if (!PendingAcks.ContainsKey(sequence)) { PendingAcks[sequence] = sequence; }
if (!m_pendingAcks.ContainsKey(sequence)) { m_pendingAcks[sequence] = sequence; }
}
}*/
}
@ -2487,9 +2517,9 @@ namespace OpenSim.Region.ClientStack
{
int now = System.Environment.TickCount;
lock (NeedAck)
lock (m_needAck)
{
foreach (Packet packet in NeedAck.Values)
foreach (Packet packet in m_needAck.Values)
{
if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent))
{
@ -2505,11 +2535,11 @@ namespace OpenSim.Region.ClientStack
protected void SendAcks()
{
lock (PendingAcks)
lock (m_pendingAcks)
{
if (PendingAcks.Count > 0)
if (m_pendingAcks.Count > 0)
{
if (PendingAcks.Count > 250)
if (m_pendingAcks.Count > 250)
{
// FIXME: Handle the odd case where we have too many pending ACKs queued up
MainLog.Instance.Verbose("NETWORK", "Too many ACKs queued up!");
@ -2520,9 +2550,9 @@ namespace OpenSim.Region.ClientStack
int i = 0;
PacketAckPacket acks = new PacketAckPacket();
acks.Packets = new PacketAckPacket.PacketsBlock[PendingAcks.Count];
acks.Packets = new PacketAckPacket.PacketsBlock[m_pendingAcks.Count];
foreach (uint ack in PendingAcks.Values)
foreach (uint ack in m_pendingAcks.Values)
{
acks.Packets[i] = new PacketAckPacket.PacketsBlock();
acks.Packets[i].ID = ack;
@ -2532,7 +2562,7 @@ namespace OpenSim.Region.ClientStack
acks.Header.Reliable = false;
OutPacket(acks, ThrottleOutPacketType.Unknown);
PendingAcks.Clear();
m_pendingAcks.Clear();
}
}
}
@ -3388,7 +3418,7 @@ namespace OpenSim.Region.ClientStack
// If the client didn't send acceptable values....
// Scale the clients values down until they are acceptable.
if (tall <= throttleOutboundMax)
if (tall <= m_throttleOutboundMax)
{
// Sanity
// Making sure the client sends sane values
@ -3397,61 +3427,61 @@ namespace OpenSim.Region.ClientStack
// Then Check Min of type
// Resend throttle
if (tResend <= ResendthrottleMAX)
ResendthrottleOutbound = tResend;
if (tResend <= m_resendthrottleMAX)
m_resendthrottleOutbound = tResend;
if (tResend < ResendthrottleMin)
ResendthrottleOutbound = ResendthrottleMin;
if (tResend < m_resendthrottleMin)
m_resendthrottleOutbound = m_resendthrottleMin;
// Land throttle
if (tLand <= LandthrottleMax)
LandthrottleOutbound = tLand;
if (tLand <= m_landthrottleMax)
m_landthrottleOutbound = tLand;
if (tLand < LandthrottleMin)
LandthrottleOutbound = LandthrottleMin;
if (tLand < m_landthrottleMin)
m_landthrottleOutbound = m_landthrottleMin;
// Wind throttle
if (tWind <= WindthrottleMax)
WindthrottleOutbound = tWind;
if (tWind <= m_windthrottleMax)
m_windthrottleOutbound = tWind;
if (tWind < WindthrottleMin)
WindthrottleOutbound = WindthrottleMin;
if (tWind < m_windthrottleMin)
m_windthrottleOutbound = m_windthrottleMin;
// Cloud throttle
if (tCloud <= CloudthrottleMax)
CloudthrottleOutbound = tCloud;
if (tCloud <= m_cloudthrottleMax)
m_cloudthrottleOutbound = tCloud;
if (tCloud < CloudthrottleMin)
CloudthrottleOutbound = CloudthrottleMin;
if (tCloud < m_cloudthrottleMin)
m_cloudthrottleOutbound = m_cloudthrottleMin;
// Task throttle
if (tTask <= TaskthrottleMax)
TaskthrottleOutbound = tTask;
if (tTask <= m_taskthrottleMax)
m_taskthrottleOutbound = tTask;
if (tTask < TaskthrottleMin)
TaskthrottleOutbound = TaskthrottleMin;
if (tTask < m_taskthrottleMin)
m_taskthrottleOutbound = m_taskthrottleMin;
// Texture throttle
if (tTexture <= TexturethrottleMax)
TexturethrottleOutbound = tTexture;
if (tTexture <= m_texturethrottleMax)
m_texturethrottleOutbound = tTexture;
if (tTexture < TexturethrottleMin)
TexturethrottleOutbound = TexturethrottleMin;
if (tTexture < m_texturethrottleMin)
m_texturethrottleOutbound = m_texturethrottleMin;
//Asset throttle
if (tAsset <= AssetthrottleMax)
AssetthrottleOutbound = tAsset;
if (tAsset <= m_assetthrottleMax)
m_assetthrottleOutbound = tAsset;
if (tAsset < AssetthrottleMin)
AssetthrottleOutbound = AssetthrottleMin;
if (tAsset < m_assetthrottleMin)
m_assetthrottleOutbound = m_assetthrottleMin;
/* MainLog.Instance.Verbose("THROTTLE", "Using:resendbytes=" + ResendthrottleOutbound +
" landbytes=" + LandthrottleOutbound +
" windbytes=" + WindthrottleOutbound +
" cloudbytes=" + CloudthrottleOutbound +
" taskbytes=" + TaskthrottleOutbound +
" texturebytes=" + TexturethrottleOutbound +
" Assetbytes=" + AssetthrottleOutbound +
/* MainLog.Instance.Verbose("THROTTLE", "Using:resendbytes=" + m_resendthrottleOutbound +
" landbytes=" + m_landthrottleOutbound +
" windbytes=" + m_windthrottleOutbound +
" cloudbytes=" + m_cloudthrottleOutbound +
" taskbytes=" + m_taskthrottleOutbound +
" texturebytes=" + m_texturethrottleOutbound +
" Assetbytes=" + m_assetthrottleOutbound +
" Allbytes=" + tall);
*/
}
@ -3471,23 +3501,23 @@ namespace OpenSim.Region.ClientStack
// it's client recommended level (won't scale it down)
// unless it's beyond sane values itself.
if (tResend <= ResendthrottleMAX)
if (tResend <= m_resendthrottleMAX)
{
// This is nexted because we only want to re-set the values
// the packet throttler uses once.
if (tResend >= ResendthrottleMin)
if (tResend >= m_resendthrottleMin)
{
ResendthrottleOutbound = tResend;
m_resendthrottleOutbound = tResend;
}
else
{
ResendthrottleOutbound = ResendthrottleMin;
m_resendthrottleOutbound = m_resendthrottleMin;
}
}
else
{
ResendthrottleOutbound = ResendthrottleMAX;
m_resendthrottleOutbound = m_resendthrottleMAX;
}
@ -3502,12 +3532,12 @@ namespace OpenSim.Region.ClientStack
// Okay.. now we've got the percentages of total communication.
// Apply them to a new max total
int tLandResult = (int)(LandPercent * throttleOutboundMax);
int tWindResult = (int)(WindPercent * throttleOutboundMax);
int tCloudResult = (int)(CloudPercent * throttleOutboundMax);
int tTaskResult = (int)(TaskPercent * throttleOutboundMax);
int tTextureResult = (int)(TexturePercent * throttleOutboundMax);
int tAssetResult = (int)(AssetPercent * throttleOutboundMax);
int tLandResult = (int)(LandPercent * m_throttleOutboundMax);
int tWindResult = (int)(WindPercent * m_throttleOutboundMax);
int tCloudResult = (int)(CloudPercent * m_throttleOutboundMax);
int tTaskResult = (int)(TaskPercent * m_throttleOutboundMax);
int tTextureResult = (int)(TexturePercent * m_throttleOutboundMax);
int tAssetResult = (int)(AssetPercent * m_throttleOutboundMax);
// Now we have to check our scaled values for sanity
@ -3515,54 +3545,54 @@ namespace OpenSim.Region.ClientStack
// Then Check Min of type
// Land throttle
if (tLandResult <= LandthrottleMax)
LandthrottleOutbound = tLandResult;
if (tLandResult <= m_landthrottleMax)
m_landthrottleOutbound = tLandResult;
if (tLandResult < LandthrottleMin)
LandthrottleOutbound = LandthrottleMin;
if (tLandResult < m_landthrottleMin)
m_landthrottleOutbound = m_landthrottleMin;
// Wind throttle
if (tWindResult <= WindthrottleMax)
WindthrottleOutbound = tWindResult;
if (tWindResult <= m_windthrottleMax)
m_windthrottleOutbound = tWindResult;
if (tWindResult < WindthrottleMin)
WindthrottleOutbound = WindthrottleMin;
if (tWindResult < m_windthrottleMin)
m_windthrottleOutbound = m_windthrottleMin;
// Cloud throttle
if (tCloudResult <= CloudthrottleMax)
CloudthrottleOutbound = tCloudResult;
if (tCloudResult <= m_cloudthrottleMax)
m_cloudthrottleOutbound = tCloudResult;
if (tCloudResult < CloudthrottleMin)
CloudthrottleOutbound = CloudthrottleMin;
if (tCloudResult < m_cloudthrottleMin)
m_cloudthrottleOutbound = m_cloudthrottleMin;
// Task throttle
if (tTaskResult <= TaskthrottleMax)
TaskthrottleOutbound = tTaskResult;
if (tTaskResult <= m_taskthrottleMax)
m_taskthrottleOutbound = tTaskResult;
if (tTaskResult < TaskthrottleMin)
TaskthrottleOutbound = TaskthrottleMin;
if (tTaskResult < m_taskthrottleMin)
m_taskthrottleOutbound = m_taskthrottleMin;
// Texture throttle
if (tTextureResult <= TexturethrottleMax)
TexturethrottleOutbound = tTextureResult;
if (tTextureResult <= m_texturethrottleMax)
m_texturethrottleOutbound = tTextureResult;
if (tTextureResult < TexturethrottleMin)
TexturethrottleOutbound = TexturethrottleMin;
if (tTextureResult < m_texturethrottleMin)
m_texturethrottleOutbound = m_texturethrottleMin;
//Asset throttle
if (tAssetResult <= AssetthrottleMax)
AssetthrottleOutbound = tAssetResult;
if (tAssetResult <= m_assetthrottleMax)
m_assetthrottleOutbound = tAssetResult;
if (tAssetResult < AssetthrottleMin)
AssetthrottleOutbound = AssetthrottleMin;
if (tAssetResult < m_assetthrottleMin)
m_assetthrottleOutbound = m_assetthrottleMin;
/* MainLog.Instance.Verbose("THROTTLE", "Using:resendbytes=" + ResendthrottleOutbound +
" landbytes=" + LandthrottleOutbound +
" windbytes=" + WindthrottleOutbound +
" cloudbytes=" + CloudthrottleOutbound +
" taskbytes=" + TaskthrottleOutbound +
" texturebytes=" + TexturethrottleOutbound +
" Assetbytes=" + AssetthrottleOutbound +
/* MainLog.Instance.Verbose("THROTTLE", "Using:resendbytes=" + m_resendthrottleOutbound +
" landbytes=" + m_landthrottleOutbound +
" windbytes=" + m_windthrottleOutbound +
" cloudbytes=" + m_cloudthrottleOutbound +
" taskbytes=" + m_taskthrottleOutbound +
" texturebytes=" + m_texturethrottleOutbound +
" Assetbytes=" + m_assetthrottleOutbound +
" Allbytes=" + tall);
*/
}
@ -3570,20 +3600,20 @@ namespace OpenSim.Region.ClientStack
{
// The client sent a stupid value..
// We're going to set the throttles to the minimum possible
ResendthrottleOutbound = ResendthrottleMin;
LandthrottleOutbound = LandthrottleMin;
WindthrottleOutbound = WindthrottleMin;
CloudthrottleOutbound = CloudthrottleMin;
TaskthrottleOutbound = TaskthrottleMin;
TexturethrottleOutbound = TexturethrottleMin;
AssetthrottleOutbound = AssetthrottleMin;
MainLog.Instance.Verbose("THROTTLE", "ClientSentBadThrottle Using:resendbytes=" + ResendthrottleOutbound +
" landbytes=" + LandthrottleOutbound +
" windbytes=" + WindthrottleOutbound +
" cloudbytes=" + CloudthrottleOutbound +
" taskbytes=" + TaskthrottleOutbound +
" texturebytes=" + TexturethrottleOutbound +
" Assetbytes=" + AssetthrottleOutbound +
m_resendthrottleOutbound = m_resendthrottleMin;
m_landthrottleOutbound = m_landthrottleMin;
m_windthrottleOutbound = m_windthrottleMin;
m_cloudthrottleOutbound = m_cloudthrottleMin;
m_taskthrottleOutbound = m_taskthrottleMin;
m_texturethrottleOutbound = m_texturethrottleMin;
m_assetthrottleOutbound = m_assetthrottleMin;
MainLog.Instance.Verbose("THROTTLE", "ClientSentBadThrottle Using:resendbytes=" + m_resendthrottleOutbound +
" landbytes=" + m_landthrottleOutbound +
" windbytes=" + m_windthrottleOutbound +
" cloudbytes=" + m_cloudthrottleOutbound +
" taskbytes=" + m_taskthrottleOutbound +
" texturebytes=" + m_texturethrottleOutbound +
" Assetbytes=" + m_assetthrottleOutbound +
" Allbytes=" + tall);
}
}
@ -3591,13 +3621,13 @@ namespace OpenSim.Region.ClientStack
// This has the effect of 'wiggling the slider
// causes prim and stuck textures that didn't download to download
ResendBytesSent = 0;
LandBytesSent = 0;
WindBytesSent = 0;
CloudBytesSent = 0;
TaskBytesSent = 0;
AssetBytesSent = 0;
TextureBytesSent = 0;
m_resendBytesSent = 0;
m_landBytesSent = 0;
m_windBytesSent = 0;
m_cloudBytesSent = 0;
m_taskBytesSent = 0;
m_assetBytesSent = 0;
m_textureBytesSent = 0;
//Yay, we've finally handled the agent Throttle packet!
break;

View File

@ -396,6 +396,7 @@ namespace OpenSim.Region.Environment.Scenes
module.Close();
}
}
Modules.Clear();
base.Close();