Improved avatar responsiveness.

This commit is contained in:
CasperW
2009-11-21 15:36:38 +01:00
committed by Melanie
parent 0844e5951c
commit 0149265ee8
6 changed files with 164 additions and 49 deletions

View File

@@ -3121,7 +3121,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
objupdate.ObjectData[0] = CreateAvatarUpdateBlock(data);
OutPacket(objupdate, ThrottleOutPacketType.Task);
}
@@ -3172,8 +3171,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
terse.ObjectData[i] = m_avatarTerseUpdates.Dequeue();
}
// HACK: Using the task category until the tiered reprioritization code is in
OutPacket(terse, ThrottleOutPacketType.Task);
OutPacket(terse, ThrottleOutPacketType.State);
}
public void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations)

View File

@@ -571,23 +571,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP
//Sorry, i know it's not optimal, but until the LL client
//manages packets correctly and re-orders them as required, this is necessary.
if (outgoingPacket.Type == PacketType.ImprovedTerseObjectUpdate
|| outgoingPacket.Type == PacketType.ChatFromSimulator
|| outgoingPacket.Type == PacketType.ObjectUpdate
// Put the UDP payload on the wire
if (outgoingPacket.Type == PacketType.ImprovedTerseObjectUpdate)
{
SyncBeginPrioritySend(buffer, 2); // highest priority
}
else if (outgoingPacket.Type == PacketType.ObjectUpdate
|| outgoingPacket.Type == PacketType.ChatFromSimulator
|| outgoingPacket.Type == PacketType.LayerData)
{
sendSynchronous = true;
}
// Put the UDP payload on the wire
if (sendSynchronous == true)
{
SyncBeginSend(buffer);
SyncBeginPrioritySend(buffer, 1); // medium priority
}
else
{
AsyncBeginSend(buffer);
SyncBeginPrioritySend(buffer, 0); // normal priority
}
//AsyncBeginSend(buffer);
// Keep track of when this packet was sent out (right now)
outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue;
}
@@ -862,7 +864,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
Buffer.BlockCopy(packetData, 0, buffer.Data, 0, length);
AsyncBeginSend(buffer);
SyncBeginPrioritySend(buffer, 1); //Setting this to a medium priority should help minimise resends
}
private bool IsClientAuthorized(UseCircuitCodePacket useCircuitCode, out AuthenticateResponse sessionInfo)

View File

@@ -29,6 +29,7 @@ using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Generic;
using log4net;
namespace OpenMetaverse
@@ -52,12 +53,25 @@ namespace OpenMetaverse
/// <summary>Local IP address to bind to in server mode</summary>
protected IPAddress m_localBindAddress;
/// <summary>
/// Standard queue for our outgoing SyncBeginPrioritySend
/// </summary>
private List<UDPPacketBuffer> m_standardQueue = new List<UDPPacketBuffer>();
/// <summary>
/// Prioritised queue for our outgoing SyncBeginPrioritySend
/// </summary>
private List<UDPPacketBuffer> m_priorityQueue = new List<UDPPacketBuffer>();
/// <summary>UDP socket, used in either client or server mode</summary>
private Socket m_udpSocket;
/// <summary>Flag to process packets asynchronously or synchronously</summary>
private bool m_asyncPacketHandling;
/// <summary>Are we currently sending data asynchronously?</summary>
private volatile bool m_sendingData = false;
/// <summary>The all important shutdown flag</summary>
private volatile bool m_shutdownFlag = true;
@@ -246,25 +260,48 @@ namespace OpenMetaverse
}
}
public void SyncBeginSend(UDPPacketBuffer buf)
public void SyncBeginPrioritySend(UDPPacketBuffer buf, int Priority)
{
if (!m_shutdownFlag)
{
try
if (!m_sendingData)
{
m_udpSocket.SendTo(
buf.Data,
0,
buf.DataLength,
SocketFlags.None,
buf.RemoteEndPoint);
m_sendingData = true;
try
{
AsyncBeginSend(buf);
}
catch (SocketException) { }
catch (ObjectDisposedException) { }
}
else
{
if (Priority == 2)
{
lock (m_priorityQueue)
{
m_priorityQueue.Add(buf);
}
}
else
{
lock (m_standardQueue)
{
if (Priority != 0)
{
m_standardQueue.Insert(0, buf);
}
else
{
m_standardQueue.Add(buf);
}
}
}
}
catch (SocketException) { }
catch (ObjectDisposedException) { }
}
}
public void AsyncBeginSend(UDPPacketBuffer buf)
private void AsyncBeginSend(UDPPacketBuffer buf)
{
if (!m_shutdownFlag)
{
@@ -288,8 +325,36 @@ namespace OpenMetaverse
{
try
{
// UDPPacketBuffer buf = (UDPPacketBuffer)result.AsyncState;
m_udpSocket.EndSendTo(result);
if (m_sendingData)
{
lock (m_priorityQueue)
{
if (m_priorityQueue.Count > 0)
{
UDPPacketBuffer buf = m_priorityQueue[0];
m_priorityQueue.RemoveAt(0);
AsyncBeginSend(buf);
}
else
{
lock (m_standardQueue)
{
if (m_standardQueue.Count > 0)
{
UDPPacketBuffer buf = m_standardQueue[0];
m_standardQueue.RemoveAt(0);
AsyncBeginSend(buf);
}
else
{
m_sendingData = false;
}
}
}
}
}
}
catch (SocketException) { }
catch (ObjectDisposedException) { }