* Changed the timing calculations for sending resends/acks/pings from per-client back to per-scene

* Testing a fix from Jim to make the cpu usage fix cleaner
prioritization
John Hurliman 2009-10-21 15:22:23 -07:00
parent 62f1bfd136
commit 2752a3525c
3 changed files with 63 additions and 41 deletions

View File

@ -3558,7 +3558,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
ProcessTextureRequests(); ProcessTextureRequests();
break; break;
case ThrottleOutPacketType.Task: case ThrottleOutPacketType.Task:
if (Monitor.TryEnter(m_avatarTerseUpdates.SyncRoot, 1)) if (Monitor.TryEnter(m_avatarTerseUpdates.SyncRoot))
{ {
try try
{ {
@ -3573,7 +3573,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
break; break;
case ThrottleOutPacketType.State: case ThrottleOutPacketType.State:
if (Monitor.TryEnter(m_primFullUpdates.SyncRoot, 1)) if (Monitor.TryEnter(m_primFullUpdates.SyncRoot))
{ {
try try
{ {
@ -3586,7 +3586,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
finally { Monitor.Exit(m_primFullUpdates.SyncRoot); } finally { Monitor.Exit(m_primFullUpdates.SyncRoot); }
} }
if (Monitor.TryEnter(m_primTerseUpdates.SyncRoot, 1)) if (Monitor.TryEnter(m_primTerseUpdates.SyncRoot))
{ {
try try
{ {

View File

@ -103,14 +103,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public bool IsPaused; public bool IsPaused;
/// <summary>Environment.TickCount when the last packet was received for this client</summary> /// <summary>Environment.TickCount when the last packet was received for this client</summary>
public int TickLastPacketReceived; public int TickLastPacketReceived;
/// <summary>Environment.TickCount of the last time the outgoing packet handler executed for this client</summary>
public int TickLastOutgoingPacketHandler;
/// <summary>Keeps track of the number of elapsed milliseconds since the last time the outgoing packet handler executed for this client</summary>
public int ElapsedMSOutgoingPacketHandler;
/// <summary>Keeps track of the number of 100 millisecond periods elapsed in the outgoing packet handler executed for this client</summary>
public int Elapsed100MSOutgoingPacketHandler;
/// <summary>Keeps track of the number of 500 millisecond periods elapsed in the outgoing packet handler executed for this client</summary>
public int Elapsed500MSOutgoingPacketHandler;
/// <summary>Smoothed round-trip time. A smoothed average of the round-trip time for sending a /// <summary>Smoothed round-trip time. A smoothed average of the round-trip time for sending a
/// reliable packet to the client and receiving an ACK</summary> /// reliable packet to the client and receiving an ACK</summary>
@ -191,9 +183,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// Initialize this to a sane value to prevent early disconnects // Initialize this to a sane value to prevent early disconnects
TickLastPacketReceived = Environment.TickCount & Int32.MaxValue; TickLastPacketReceived = Environment.TickCount & Int32.MaxValue;
ElapsedMSOutgoingPacketHandler = 0;
Elapsed100MSOutgoingPacketHandler = 0;
Elapsed500MSOutgoingPacketHandler = 0;
} }
/// <summary> /// <summary>
@ -553,7 +542,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
// HACK: Try spending some extra time here to slow down OnQueueEmpty calls // HACK: Try spending some extra time here to slow down OnQueueEmpty calls
System.Threading.Thread.Sleep(100); //System.Threading.Thread.Sleep(100);
m_onQueueEmptyRunning[i] = false; m_onQueueEmptyRunning[i] = false;
} }

View File

@ -125,6 +125,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// whether or not to sleep</summary> /// whether or not to sleep</summary>
private bool m_packetSent; private bool m_packetSent;
/// <summary>Environment.TickCount of the last time the outgoing packet handler executed</summary>
private int m_tickLastOutgoingPacketHandler;
/// <summary>Keeps track of the number of elapsed milliseconds since the last time the outgoing packet handler looped</summary>
private int m_elapsedMSOutgoingPacketHandler;
/// <summary>Keeps track of the number of 100 millisecond periods elapsed in the outgoing packet handler executed</summary>
private int m_elapsed100MSOutgoingPacketHandler;
/// <summary>Keeps track of the number of 500 millisecond periods elapsed in the outgoing packet handler executed</summary>
private int m_elapsed500MSOutgoingPacketHandler;
/// <summary>Flag to signal when clients should check for resends</summary>
private bool m_resendUnacked;
/// <summary>Flag to signal when clients should send ACKs</summary>
private bool m_sendAcks;
/// <summary>Flag to signal when clients should send pings</summary>
private bool m_sendPing;
public Socket Server { get { return null; } } public Socket Server { get { return null; } }
public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager)
@ -786,6 +802,46 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{ {
m_packetSent = false; m_packetSent = false;
#region Update Timers
m_resendUnacked = false;
m_sendAcks = false;
m_sendPing = false;
// Update elapsed time
int thisTick = Environment.TickCount & Int32.MaxValue;
if (m_tickLastOutgoingPacketHandler > thisTick)
m_elapsedMSOutgoingPacketHandler += ((Int32.MaxValue - m_tickLastOutgoingPacketHandler) + thisTick);
else
m_elapsedMSOutgoingPacketHandler += (thisTick - m_tickLastOutgoingPacketHandler);
m_tickLastOutgoingPacketHandler = thisTick;
// Check for pending outgoing resends every 100ms
if (m_elapsedMSOutgoingPacketHandler >= 100)
{
m_resendUnacked = true;
m_elapsedMSOutgoingPacketHandler = 0;
m_elapsed100MSOutgoingPacketHandler += 1;
}
// Check for pending outgoing ACKs every 500ms
if (m_elapsed100MSOutgoingPacketHandler >= 5)
{
m_sendAcks = true;
m_elapsed100MSOutgoingPacketHandler = 0;
m_elapsed500MSOutgoingPacketHandler += 1;
}
// Send pings to clients every 5000ms
if (m_elapsed500MSOutgoingPacketHandler >= 10)
{
m_sendPing = true;
m_elapsed500MSOutgoingPacketHandler = 0;
}
#endregion Update Timers
// Handle outgoing packets, resends, acknowledgements, and pings for each // Handle outgoing packets, resends, acknowledgements, and pings for each
// client. m_packetSent will be set to true if a packet is sent // client. m_packetSent will be set to true if a packet is sent
m_scene.ClientManager.ForEachSync(ClientOutgoingPacketHandler); m_scene.ClientManager.ForEachSync(ClientOutgoingPacketHandler);
@ -810,44 +866,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{ {
LLUDPClient udpClient = ((LLClientView)client).UDPClient; LLUDPClient udpClient = ((LLClientView)client).UDPClient;
// Update ElapsedMSOutgoingPacketHandler
int thisTick = Environment.TickCount & Int32.MaxValue;
if (udpClient.TickLastOutgoingPacketHandler > thisTick)
udpClient.ElapsedMSOutgoingPacketHandler += ((Int32.MaxValue - udpClient.TickLastOutgoingPacketHandler) + thisTick);
else
udpClient.ElapsedMSOutgoingPacketHandler += (thisTick - udpClient.TickLastOutgoingPacketHandler);
if (udpClient.IsConnected) if (udpClient.IsConnected)
{ {
// Check for pending outgoing resends every 100ms if (m_resendUnacked)
if (udpClient.ElapsedMSOutgoingPacketHandler >= 100)
{
ResendUnacked(udpClient); ResendUnacked(udpClient);
udpClient.ElapsedMSOutgoingPacketHandler = 0;
udpClient.Elapsed100MSOutgoingPacketHandler += 1;
}
// Check for pending outgoing ACKs every 500ms if (m_sendAcks)
if (udpClient.Elapsed100MSOutgoingPacketHandler >= 5)
{
SendAcks(udpClient); SendAcks(udpClient);
udpClient.Elapsed100MSOutgoingPacketHandler = 0;
udpClient.Elapsed500MSOutgoingPacketHandler += 1;
}
// Send pings to clients every 5000ms if (m_sendPing)
if (udpClient.Elapsed500MSOutgoingPacketHandler >= 10)
{
SendPing(udpClient); SendPing(udpClient);
udpClient.Elapsed500MSOutgoingPacketHandler = 0;
}
// Dequeue any outgoing packets that are within the throttle limits // Dequeue any outgoing packets that are within the throttle limits
if (udpClient.DequeueOutgoing()) if (udpClient.DequeueOutgoing())
m_packetSent = true; m_packetSent = true;
} }
udpClient.TickLastOutgoingPacketHandler = thisTick;
} }
} }
catch (Exception ex) catch (Exception ex)