Reapply the packet optimization patch, with changes

0.6.1-post-fixes
Melanie Thielker 2008-12-17 21:00:18 +00:00
parent dce11e4685
commit a9e38bcafc
3 changed files with 42 additions and 57 deletions

View File

@ -99,26 +99,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// //
private Dictionary<uint, uint> m_PendingAcks = new Dictionary<uint, uint>(); private Dictionary<uint, uint> m_PendingAcks = new Dictionary<uint, uint>();
// Dictionary of the packets that need acks from the client. private Dictionary<uint, LLQueItem> m_NeedAck =
// new Dictionary<uint, LLQueItem>();
private class AckData
{
public AckData(Packet packet, Object identifier, int tickCount, int resends)
{
Packet = packet;
Identifier = identifier;
TickCount = tickCount;
Resends = resends;
}
public Packet Packet;
public Object Identifier;
public int TickCount;
public int Resends;
}
private Dictionary<uint, AckData> m_NeedAck =
new Dictionary<uint, AckData>();
/// <summary> /// <summary>
/// The number of milliseconds that can pass before a packet that needs an ack is resent. /// The number of milliseconds that can pass before a packet that needs an ack is resent.
@ -314,6 +296,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
item.throttleType = throttlePacketType; item.throttleType = throttlePacketType;
item.TickCount = System.Environment.TickCount; item.TickCount = System.Environment.TickCount;
item.Identifier = id; item.Identifier = id;
item.Resends = 0;
item.Length = packet.ToBytes().Length;
m_PacketQueue.Enqueue(item); m_PacketQueue.Enqueue(item);
m_PacketsSent++; m_PacketsSent++;
@ -333,7 +317,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (m_DropSafeTimeout > now || if (m_DropSafeTimeout > now ||
intervalMs > 500) // We were frozen! intervalMs > 500) // We were frozen!
{ {
foreach (AckData data in new List<AckData> foreach (LLQueItem data in new List<LLQueItem>
(m_NeedAck.Values)) (m_NeedAck.Values))
{ {
if (m_DropSafeTimeout > now) if (m_DropSafeTimeout > now)
@ -364,7 +348,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
int resent = 0; int resent = 0;
foreach (AckData data in new List<AckData>(m_NeedAck.Values)) foreach (LLQueItem data in new List<LLQueItem>(m_NeedAck.Values))
{ {
Packet packet = data.Packet; Packet packet = data.Packet;
@ -630,7 +614,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private void ProcessAck(uint id) private void ProcessAck(uint id)
{ {
AckData data; LLQueItem data;
Packet packet; Packet packet;
lock (m_NeedAck) lock (m_NeedAck)
@ -640,11 +624,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (!m_NeedAck.TryGetValue(id, out data)) if (!m_NeedAck.TryGetValue(id, out data))
return; return;
packet = data.Packet;
m_NeedAck.Remove(id); m_NeedAck.Remove(id);
m_UnackedBytes -= packet.ToBytes().Length;
PacketPool.Instance.ReturnPacket(data.Packet); PacketPool.Instance.ReturnPacket(data.Packet);
m_UnackedBytes -= data.Length;
} }
} }
@ -697,7 +679,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public void SetClientInfo(ClientInfo info) public void SetClientInfo(ClientInfo info)
{ {
m_PendingAcks = info.pendingAcks; m_PendingAcks = info.pendingAcks;
m_NeedAck = new Dictionary<uint, AckData>(); m_NeedAck = new Dictionary<uint, LLQueItem>();
Packet packet = null; Packet packet = null;
int packetEnd = 0; int packetEnd = 0;
@ -716,7 +698,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{ {
} }
m_NeedAck.Add(key, new AckData(packet, null, System.Environment.TickCount, 0)); LLQueItem item = new LLQueItem();
item.Packet = packet;
item.Incoming = false;
item.throttleType = 0;
item.TickCount = System.Environment.TickCount;
item.Identifier = 0;
item.Resends = 0;
item.Length = packet.ToBytes().Length;
m_NeedAck.Add(key, item);
} }
m_Sequence = info.sequence; m_Sequence = info.sequence;
@ -740,7 +730,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private void DropResend(Object id) private void DropResend(Object id)
{ {
foreach (AckData data in new List<AckData>(m_NeedAck.Values)) foreach (LLQueItem data in new List<LLQueItem>(m_NeedAck.Values))
{ {
if (data.Identifier != null && data.Identifier == id) if (data.Identifier != null && data.Identifier == id)
{ {
@ -777,12 +767,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// We want to see that packet arrive if it's reliable // We want to see that packet arrive if it's reliable
if (packet.Header.Reliable) if (packet.Header.Reliable)
{ {
m_UnackedBytes += packet.ToBytes().Length; m_UnackedBytes += item.Length;
// Keep track of when this packet was sent out // Keep track of when this packet was sent out
m_NeedAck[packet.Header.Sequence] = new AckData(packet, item.TickCount = System.Environment.TickCount;
item.Identifier, System.Environment.TickCount,
0); m_NeedAck[packet.Header.Sequence] = item;
} }
} }
} }
@ -792,7 +782,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
Abort(); Abort();
// Actually make the byte array and send it // Actually make the byte array and send it
byte[] sendbuffer = packet.ToBytes(); byte[] sendbuffer = item.Packet.ToBytes();
//m_log.DebugFormat( //m_log.DebugFormat(
// "[CLIENT]: In {0} sending packet {1}", // "[CLIENT]: In {0} sending packet {1}",

View File

@ -345,9 +345,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
LLQueItem qpack = ResendOutgoingPacketQueue.Dequeue(); LLQueItem qpack = ResendOutgoingPacketQueue.Dequeue();
SendQueue.Enqueue(qpack); SendQueue.Enqueue(qpack);
int qpackSize = qpack.Packet.ToBytes().Length; TotalThrottle.AddBytes(qpack.Length);
TotalThrottle.AddBytes(qpackSize); ResendThrottle.AddBytes(qpack.Length);
ResendThrottle.AddBytes(qpackSize);
qchanged = true; qchanged = true;
} }
@ -357,9 +356,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
LLQueItem qpack = LandOutgoingPacketQueue.Dequeue(); LLQueItem qpack = LandOutgoingPacketQueue.Dequeue();
SendQueue.Enqueue(qpack); SendQueue.Enqueue(qpack);
int qpackSize = qpack.Packet.ToBytes().Length; TotalThrottle.AddBytes(qpack.Length);
TotalThrottle.AddBytes(qpackSize); LandThrottle.AddBytes(qpack.Length);
LandThrottle.AddBytes(qpackSize);
qchanged = true; qchanged = true;
} }
@ -368,9 +366,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
LLQueItem qpack = WindOutgoingPacketQueue.Dequeue(); LLQueItem qpack = WindOutgoingPacketQueue.Dequeue();
SendQueue.Enqueue(qpack); SendQueue.Enqueue(qpack);
int qpackSize = qpack.Packet.ToBytes().Length; TotalThrottle.AddBytes(qpack.Length);
TotalThrottle.AddBytes(qpackSize); WindThrottle.AddBytes(qpack.Length);
WindThrottle.AddBytes(qpackSize);
qchanged = true; qchanged = true;
} }
@ -379,9 +376,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
LLQueItem qpack = CloudOutgoingPacketQueue.Dequeue(); LLQueItem qpack = CloudOutgoingPacketQueue.Dequeue();
SendQueue.Enqueue(qpack); SendQueue.Enqueue(qpack);
int qpackSize = qpack.Packet.ToBytes().Length; TotalThrottle.AddBytes(qpack.Length);
TotalThrottle.AddBytes(qpackSize); CloudThrottle.AddBytes(qpack.Length);
CloudThrottle.AddBytes(qpackSize);
qchanged = true; qchanged = true;
} }
@ -399,9 +395,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
SendQueue.Enqueue(qpack); SendQueue.Enqueue(qpack);
} }
int qpackSize = qpack.Packet.ToBytes().Length; TotalThrottle.AddBytes(qpack.Length);
TotalThrottle.AddBytes(qpackSize); TaskThrottle.AddBytes(qpack.Length);
TaskThrottle.AddBytes(qpackSize);
qchanged = true; qchanged = true;
} }
@ -410,9 +405,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
LLQueItem qpack = TextureOutgoingPacketQueue.Dequeue(); LLQueItem qpack = TextureOutgoingPacketQueue.Dequeue();
SendQueue.Enqueue(qpack); SendQueue.Enqueue(qpack);
int qpackSize = qpack.Packet.ToBytes().Length; TotalThrottle.AddBytes(qpack.Length);
TotalThrottle.AddBytes(qpackSize); TextureThrottle.AddBytes(qpack.Length);
TextureThrottle.AddBytes(qpackSize);
qchanged = true; qchanged = true;
} }
@ -421,9 +415,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
LLQueItem qpack = AssetOutgoingPacketQueue.Dequeue(); LLQueItem qpack = AssetOutgoingPacketQueue.Dequeue();
SendQueue.Enqueue(qpack); SendQueue.Enqueue(qpack);
int qpackSize = qpack.Packet.ToBytes().Length; TotalThrottle.AddBytes(qpack.Length);
TotalThrottle.AddBytes(qpackSize); AssetThrottle.AddBytes(qpack.Length);
AssetThrottle.AddBytes(qpackSize);
qchanged = true; qchanged = true;
} }
} }
@ -451,8 +444,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
try try
{ {
Monitor.Enter(this); Monitor.Enter(this);
throttle.AddBytes(item.Packet.ToBytes().Length); throttle.AddBytes(item.Length);
TotalThrottle.AddBytes(item.Packet.ToBytes().Length); TotalThrottle.AddBytes(item.Length);
SendQueue.Enqueue(item); SendQueue.Enqueue(item);
} }
catch (Exception e) catch (Exception e)

View File

@ -42,5 +42,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public ThrottleOutPacketType throttleType; public ThrottleOutPacketType throttleType;
public int TickCount; public int TickCount;
public Object Identifier; public Object Identifier;
public int Resends;
public int Length;
} }
} }