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

View File

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