mirror of
https://github.com/opensim/opensim.git
synced 2026-08-01 06:06:06 +08:00
Merge branch 'master' into careminster
Conflicts: OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
This commit is contained in:
@@ -5415,9 +5415,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
AddLocalPacketHandler(PacketType.RemoveTaskInventory, HandleRemoveTaskInventory);
|
||||
AddLocalPacketHandler(PacketType.MoveTaskInventory, HandleMoveTaskInventory);
|
||||
AddLocalPacketHandler(PacketType.RezScript, HandleRezScript);
|
||||
AddLocalPacketHandler(PacketType.MapLayerRequest, HandleMapLayerRequest, false);
|
||||
AddLocalPacketHandler(PacketType.MapBlockRequest, HandleMapBlockRequest, false);
|
||||
AddLocalPacketHandler(PacketType.MapNameRequest, HandleMapNameRequest, false);
|
||||
AddLocalPacketHandler(PacketType.MapLayerRequest, HandleMapLayerRequest);
|
||||
AddLocalPacketHandler(PacketType.MapBlockRequest, HandleMapBlockRequest);
|
||||
AddLocalPacketHandler(PacketType.MapNameRequest, HandleMapNameRequest);
|
||||
AddLocalPacketHandler(PacketType.TeleportLandmarkRequest, HandleTeleportLandmarkRequest);
|
||||
AddLocalPacketHandler(PacketType.TeleportCancel, HandleTeleportCancel);
|
||||
AddLocalPacketHandler(PacketType.TeleportLocationRequest, HandleTeleportLocationRequest);
|
||||
|
||||
@@ -70,6 +70,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
public void AddScene(IScene scene)
|
||||
{
|
||||
m_udpServer.AddScene(scene);
|
||||
|
||||
StatsManager.RegisterStat(
|
||||
new Stat(
|
||||
"IncomingPacketsProcessedCount",
|
||||
"Number of inbound UDP packets processed",
|
||||
"Number of inbound UDP packets processed",
|
||||
"",
|
||||
"clientstack",
|
||||
scene.Name,
|
||||
StatType.Pull,
|
||||
stat => stat.Value = m_udpServer.IncomingPacketsProcessed,
|
||||
StatVerbosity.Debug));
|
||||
}
|
||||
|
||||
public bool HandlesRegion(Location x)
|
||||
@@ -173,6 +185,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
private ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>> m_pendingCache = new ExpiringCache<IPEndPoint, Queue<UDPPacketBuffer>>();
|
||||
private Pool<IncomingPacket> m_incomingPacketPool;
|
||||
|
||||
/// <summary>
|
||||
/// Stat for number of packets in the main pool awaiting use.
|
||||
/// </summary>
|
||||
private Stat m_poolCountStat;
|
||||
|
||||
/// <summary>
|
||||
/// Stat for number of packets in the inbound packet pool awaiting use.
|
||||
/// </summary>
|
||||
private Stat m_incomingPacketPoolStat;
|
||||
|
||||
private int m_defaultRTO = 0;
|
||||
@@ -345,20 +365,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
|
||||
m_incomingPacketPool = new Pool<IncomingPacket>(() => new IncomingPacket(), 500);
|
||||
|
||||
m_incomingPacketPoolStat
|
||||
= new Stat(
|
||||
"IncomingPacketPoolCount",
|
||||
"Objects within incoming packet pool",
|
||||
"The number of objects currently stored within the incoming packet pool",
|
||||
"",
|
||||
"clientstack",
|
||||
"packetpool",
|
||||
StatType.Pull,
|
||||
stat => stat.Value = m_incomingPacketPool.Count,
|
||||
StatVerbosity.Debug);
|
||||
|
||||
StatsManager.RegisterStat(m_incomingPacketPoolStat);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -381,6 +387,53 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is a seperate method so that it can be called once we have an m_scene to distinguish different scene
|
||||
/// stats.
|
||||
/// </summary>
|
||||
private void EnablePoolStats()
|
||||
{
|
||||
m_poolCountStat
|
||||
= new Stat(
|
||||
"UDPPacketBufferPoolCount",
|
||||
"Objects within the UDPPacketBuffer pool",
|
||||
"The number of objects currently stored within the UDPPacketBuffer pool",
|
||||
"",
|
||||
"clientstack",
|
||||
m_scene.Name,
|
||||
StatType.Pull,
|
||||
stat => stat.Value = Pool.Count,
|
||||
StatVerbosity.Debug);
|
||||
|
||||
StatsManager.RegisterStat(m_poolCountStat);
|
||||
|
||||
m_incomingPacketPoolStat
|
||||
= new Stat(
|
||||
"IncomingPacketPoolCount",
|
||||
"Objects within incoming packet pool",
|
||||
"The number of objects currently stored within the incoming packet pool",
|
||||
"",
|
||||
"clientstack",
|
||||
m_scene.Name,
|
||||
StatType.Pull,
|
||||
stat => stat.Value = m_incomingPacketPool.Count,
|
||||
StatVerbosity.Debug);
|
||||
|
||||
StatsManager.RegisterStat(m_incomingPacketPoolStat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables pool stats.
|
||||
/// </summary>
|
||||
private void DisablePoolStats()
|
||||
{
|
||||
StatsManager.DeregisterStat(m_poolCountStat);
|
||||
m_poolCountStat = null;
|
||||
|
||||
StatsManager.DeregisterStat(m_incomingPacketPoolStat);
|
||||
m_incomingPacketPoolStat = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the outgoing UDP thread times out, then return client that was being processed to help with debugging.
|
||||
/// </summary>
|
||||
@@ -420,6 +473,65 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
m_scene = (Scene)scene;
|
||||
m_location = new Location(m_scene.RegionInfo.RegionHandle);
|
||||
|
||||
// XXX: These stats are also pool stats but we register them separately since they are currently not
|
||||
// turned on and off by EnablePools()/DisablePools()
|
||||
StatsManager.RegisterStat(
|
||||
new PercentageStat(
|
||||
"PacketsReused",
|
||||
"Packets reused",
|
||||
"Number of packets reused out of all requests to the packet pool",
|
||||
"clientstack",
|
||||
m_scene.Name,
|
||||
StatType.Pull,
|
||||
stat =>
|
||||
{ PercentageStat pstat = (PercentageStat)stat;
|
||||
pstat.Consequent = PacketPool.Instance.PacketsRequested;
|
||||
pstat.Antecedent = PacketPool.Instance.PacketsReused; },
|
||||
StatVerbosity.Debug));
|
||||
|
||||
StatsManager.RegisterStat(
|
||||
new PercentageStat(
|
||||
"PacketDataBlocksReused",
|
||||
"Packet data blocks reused",
|
||||
"Number of data blocks reused out of all requests to the packet pool",
|
||||
"clientstack",
|
||||
m_scene.Name,
|
||||
StatType.Pull,
|
||||
stat =>
|
||||
{ PercentageStat pstat = (PercentageStat)stat;
|
||||
pstat.Consequent = PacketPool.Instance.BlocksRequested;
|
||||
pstat.Antecedent = PacketPool.Instance.BlocksReused; },
|
||||
StatVerbosity.Debug));
|
||||
|
||||
StatsManager.RegisterStat(
|
||||
new Stat(
|
||||
"PacketsPoolCount",
|
||||
"Objects within the packet pool",
|
||||
"The number of objects currently stored within the packet pool",
|
||||
"",
|
||||
"clientstack",
|
||||
m_scene.Name,
|
||||
StatType.Pull,
|
||||
stat => stat.Value = PacketPool.Instance.PacketsPooled,
|
||||
StatVerbosity.Debug));
|
||||
|
||||
StatsManager.RegisterStat(
|
||||
new Stat(
|
||||
"PacketDataBlocksPoolCount",
|
||||
"Objects within the packet data block pool",
|
||||
"The number of objects currently stored within the packet data block pool",
|
||||
"",
|
||||
"clientstack",
|
||||
m_scene.Name,
|
||||
StatType.Pull,
|
||||
stat => stat.Value = PacketPool.Instance.BlocksPooled,
|
||||
StatVerbosity.Debug));
|
||||
|
||||
// We delay enabling pool stats to AddScene() instead of Initialize() so that we can distinguish pool stats by
|
||||
// scene name
|
||||
if (UsePools)
|
||||
EnablePoolStats();
|
||||
|
||||
MainConsole.Instance.Commands.AddCommand(
|
||||
"Debug",
|
||||
false,
|
||||
@@ -508,12 +620,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
if (enabled == "on")
|
||||
{
|
||||
if (EnablePools())
|
||||
{
|
||||
EnablePoolStats();
|
||||
MainConsole.Instance.OutputFormat("Packet pools enabled on {0}", m_scene.Name);
|
||||
}
|
||||
}
|
||||
else if (enabled == "off")
|
||||
{
|
||||
if (DisablePools())
|
||||
{
|
||||
DisablePoolStats();
|
||||
MainConsole.Instance.OutputFormat("Packet pools disabled on {0}", m_scene.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1621,6 +1739,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
private int npacksSent = 0;
|
||||
private int npackNotSent = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Number of inbound packets processed since startup.
|
||||
/// </summary>
|
||||
public long IncomingPacketsProcessed { get; private set; }
|
||||
|
||||
private void MonitoredClientOutgoingPacketHandler(IClientAPI client)
|
||||
{
|
||||
nticks++;
|
||||
@@ -1680,7 +1803,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
npacksSent++;
|
||||
}
|
||||
else
|
||||
{
|
||||
npackNotSent++;
|
||||
}
|
||||
|
||||
watch2.Stop();
|
||||
avgDequeueTicks = (nticks - 1) / (float)nticks * avgDequeueTicks + (watch2.ElapsedTicks / (float)nticks);
|
||||
@@ -1688,7 +1813,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.WarnFormat("[LLUDPSERVER]: Client is not connected");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1752,6 +1879,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
// "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}",
|
||||
// packet.Type, client.Name, m_scene.RegionInfo.RegionName);
|
||||
// }
|
||||
|
||||
IncomingPacketsProcessed++;
|
||||
}
|
||||
|
||||
protected void LogoutHandler(IClientAPI client)
|
||||
|
||||
@@ -60,16 +60,16 @@ namespace OpenMetaverse
|
||||
/// <summary>Flag to process packets asynchronously or synchronously</summary>
|
||||
private bool m_asyncPacketHandling;
|
||||
|
||||
/// <summary>
|
||||
/// Pool to use for handling data. May be null if UsePools = false;
|
||||
/// </summary>
|
||||
protected OpenSim.Framework.Pool<UDPPacketBuffer> m_pool;
|
||||
|
||||
/// <summary>
|
||||
/// Are we to use object pool(s) to reduce memory churn when receiving data?
|
||||
/// </summary>
|
||||
public bool UsePools { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pool to use for handling data. May be null if UsePools = false;
|
||||
/// </summary>
|
||||
protected OpenSim.Framework.Pool<UDPPacketBuffer> Pool { get; private set; }
|
||||
|
||||
/// <summary>Returns true if the server is currently listening for inbound packets, otherwise false</summary>
|
||||
public bool IsRunningInbound { get; private set; }
|
||||
|
||||
@@ -77,8 +77,6 @@ namespace OpenMetaverse
|
||||
/// <remarks>If IsRunningOut = false, then any request to send a packet is simply dropped.</remarks>
|
||||
public bool IsRunningOutbound { get; private set; }
|
||||
|
||||
private Stat m_poolCountStat;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
@@ -178,21 +176,7 @@ namespace OpenMetaverse
|
||||
{
|
||||
if (!UsePools)
|
||||
{
|
||||
m_pool = new Pool<UDPPacketBuffer>(() => new UDPPacketBuffer(), 500);
|
||||
|
||||
m_poolCountStat
|
||||
= new Stat(
|
||||
"UDPPacketBufferPoolCount",
|
||||
"Objects within the UDPPacketBuffer pool",
|
||||
"The number of objects currently stored within the UDPPacketBuffer pool",
|
||||
"",
|
||||
"clientstack",
|
||||
"packetpool",
|
||||
StatType.Pull,
|
||||
stat => stat.Value = m_pool.Count,
|
||||
StatVerbosity.Debug);
|
||||
|
||||
StatsManager.RegisterStat(m_poolCountStat);
|
||||
Pool = new Pool<UDPPacketBuffer>(() => new UDPPacketBuffer(), 500);
|
||||
|
||||
UsePools = true;
|
||||
|
||||
@@ -207,7 +191,6 @@ namespace OpenMetaverse
|
||||
if (UsePools)
|
||||
{
|
||||
UsePools = false;
|
||||
StatsManager.DeregisterStat(m_poolCountStat);
|
||||
|
||||
// We won't null out the pool to avoid a race condition with code that may be in the middle of using it.
|
||||
|
||||
@@ -222,7 +205,7 @@ namespace OpenMetaverse
|
||||
UDPPacketBuffer buf;
|
||||
|
||||
if (UsePools)
|
||||
buf = m_pool.GetObject();
|
||||
buf = Pool.GetObject();
|
||||
else
|
||||
buf = new UDPPacketBuffer();
|
||||
|
||||
@@ -305,7 +288,7 @@ namespace OpenMetaverse
|
||||
finally
|
||||
{
|
||||
if (UsePools)
|
||||
m_pool.ReturnObject(buffer);
|
||||
Pool.ReturnObject(buffer);
|
||||
|
||||
// Synchronous mode waits until the packet callback completes
|
||||
// before starting the receive to fetch another packet
|
||||
@@ -347,4 +330,4 @@ namespace OpenMetaverse
|
||||
catch (ObjectDisposedException) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,29 +41,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
|
||||
private static readonly PacketPool instance = new PacketPool();
|
||||
|
||||
private bool packetPoolEnabled = true;
|
||||
private bool dataBlockPoolEnabled = true;
|
||||
|
||||
private PercentageStat m_packetsReusedStat = new PercentageStat(
|
||||
"PacketsReused",
|
||||
"Packets reused",
|
||||
"Number of packets reused out of all requests to the packet pool",
|
||||
"clientstack",
|
||||
"packetpool",
|
||||
StatType.Push,
|
||||
null,
|
||||
StatVerbosity.Debug);
|
||||
|
||||
private PercentageStat m_blocksReusedStat = new PercentageStat(
|
||||
"PacketDataBlocksReused",
|
||||
"Packet data blocks reused",
|
||||
"Number of data blocks reused out of all requests to the packet pool",
|
||||
"clientstack",
|
||||
"packetpool",
|
||||
StatType.Push,
|
||||
null,
|
||||
StatVerbosity.Debug);
|
||||
|
||||
/// <summary>
|
||||
/// Pool of packets available for reuse.
|
||||
/// </summary>
|
||||
@@ -76,46 +53,59 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
get { return instance; }
|
||||
}
|
||||
|
||||
public bool RecyclePackets
|
||||
public bool RecyclePackets { get; set; }
|
||||
|
||||
public bool RecycleDataBlocks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of packets pooled
|
||||
/// </summary>
|
||||
public int PacketsPooled
|
||||
{
|
||||
set { packetPoolEnabled = value; }
|
||||
get { return packetPoolEnabled; }
|
||||
get
|
||||
{
|
||||
lock (pool)
|
||||
return pool.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public bool RecycleDataBlocks
|
||||
/// <summary>
|
||||
/// The number of blocks pooled.
|
||||
/// </summary>
|
||||
public int BlocksPooled
|
||||
{
|
||||
set { dataBlockPoolEnabled = value; }
|
||||
get { return dataBlockPoolEnabled; }
|
||||
get
|
||||
{
|
||||
lock (DataBlocks)
|
||||
return DataBlocks.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of packets requested.
|
||||
/// </summary>
|
||||
public long PacketsRequested { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of packets reused.
|
||||
/// </summary>
|
||||
public long PacketsReused { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of packet blocks requested.
|
||||
/// </summary>
|
||||
public long BlocksRequested { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of packet blocks reused.
|
||||
/// </summary>
|
||||
public long BlocksReused { get; private set; }
|
||||
|
||||
private PacketPool()
|
||||
{
|
||||
StatsManager.RegisterStat(m_packetsReusedStat);
|
||||
StatsManager.RegisterStat(m_blocksReusedStat);
|
||||
|
||||
StatsManager.RegisterStat(
|
||||
new Stat(
|
||||
"PacketsPoolCount",
|
||||
"Objects within the packet pool",
|
||||
"The number of objects currently stored within the packet pool",
|
||||
"",
|
||||
"clientstack",
|
||||
"packetpool",
|
||||
StatType.Pull,
|
||||
stat => { lock (pool) { stat.Value = pool.Count; } },
|
||||
StatVerbosity.Debug));
|
||||
|
||||
StatsManager.RegisterStat(
|
||||
new Stat(
|
||||
"PacketDataBlocksPoolCount",
|
||||
"Objects within the packet data block pool",
|
||||
"The number of objects currently stored within the packet data block pool",
|
||||
"",
|
||||
"clientstack",
|
||||
"packetpool",
|
||||
StatType.Pull,
|
||||
stat => { lock (DataBlocks) { stat.Value = DataBlocks.Count; } },
|
||||
StatVerbosity.Debug));
|
||||
// defaults
|
||||
RecyclePackets = true;
|
||||
RecycleDataBlocks = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -125,11 +115,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
/// <returns>Guaranteed to always return a packet, whether from the pool or newly constructed.</returns>
|
||||
public Packet GetPacket(PacketType type)
|
||||
{
|
||||
m_packetsReusedStat.Consequent++;
|
||||
PacketsRequested++;
|
||||
|
||||
Packet packet;
|
||||
|
||||
if (!packetPoolEnabled)
|
||||
if (!RecyclePackets)
|
||||
return Packet.BuildPacket(type);
|
||||
|
||||
lock (pool)
|
||||
@@ -146,7 +136,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
// m_log.DebugFormat("[PACKETPOOL]: Pulling {0} packet", type);
|
||||
|
||||
// Recycle old packages
|
||||
m_packetsReusedStat.Antecedent++;
|
||||
PacketsReused++;
|
||||
|
||||
packet = pool[type].Pop();
|
||||
}
|
||||
@@ -215,7 +205,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
/// <param name="packet"></param>
|
||||
public void ReturnPacket(Packet packet)
|
||||
{
|
||||
if (dataBlockPoolEnabled)
|
||||
if (RecycleDataBlocks)
|
||||
{
|
||||
switch (packet.Type)
|
||||
{
|
||||
@@ -239,7 +229,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
}
|
||||
}
|
||||
|
||||
if (packetPoolEnabled)
|
||||
if (RecyclePackets)
|
||||
{
|
||||
switch (packet.Type)
|
||||
{
|
||||
@@ -277,7 +267,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
{
|
||||
lock (DataBlocks)
|
||||
{
|
||||
m_blocksReusedStat.Consequent++;
|
||||
BlocksRequested++;
|
||||
|
||||
Stack<Object> s;
|
||||
|
||||
@@ -285,7 +275,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
{
|
||||
if (s.Count > 0)
|
||||
{
|
||||
m_blocksReusedStat.Antecedent++;
|
||||
BlocksReused++;
|
||||
return (T)s.Pop();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user