Make PacketPool class stats pull stats instead of push stats so they can be lifted up into LLUDPServer and be distiguished by scene name
parent
b7c1a37676
commit
7e493b9665
|
@ -382,14 +382,20 @@ namespace OpenSim.Framework.Monitoring
|
||||||
|
|
||||||
public class PercentageStat : Stat
|
public class PercentageStat : Stat
|
||||||
{
|
{
|
||||||
public int Antecedent { get; set; }
|
public long Antecedent { get; set; }
|
||||||
public int Consequent { get; set; }
|
public long Consequent { get; set; }
|
||||||
|
|
||||||
public override double Value
|
public override double Value
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
int c = Consequent;
|
// Asking for an update here means that the updater cannot access this value without infinite recursion.
|
||||||
|
// XXX: A slightly messy but simple solution may be to flick a flag so we can tell if this is being
|
||||||
|
// called by the pull action and just return the value.
|
||||||
|
if (StatType == StatType.Pull)
|
||||||
|
PullAction(this);
|
||||||
|
|
||||||
|
long c = Consequent;
|
||||||
|
|
||||||
// Avoid any chance of a multi-threaded divide-by-zero
|
// Avoid any chance of a multi-threaded divide-by-zero
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
|
@ -400,7 +406,7 @@ namespace OpenSim.Framework.Monitoring
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
throw new Exception("Cannot set value on a PercentageStat");
|
throw new InvalidOperationException("Cannot set value on a PercentageStat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -469,6 +469,60 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
|
|
||||||
m_scene = (Scene)scene;
|
m_scene = (Scene)scene;
|
||||||
m_location = new Location(m_scene.RegionInfo.RegionHandle);
|
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
|
// We delay enabling pool stats to AddScene() instead of Initialize() so that we can distinguish pool stats by
|
||||||
// scene name
|
// scene name
|
||||||
|
|
|
@ -334,4 +334,4 @@ namespace OpenMetaverse
|
||||||
catch (ObjectDisposedException) { }
|
catch (ObjectDisposedException) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -41,29 +41,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
|
|
||||||
private static readonly PacketPool instance = new PacketPool();
|
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>
|
/// <summary>
|
||||||
/// Pool of packets available for reuse.
|
/// Pool of packets available for reuse.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -76,46 +53,59 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
get { return instance; }
|
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
|
||||||
get { return packetPoolEnabled; }
|
{
|
||||||
|
lock (pool)
|
||||||
|
return pool.Count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RecycleDataBlocks
|
/// <summary>
|
||||||
|
/// The number of blocks pooled.
|
||||||
|
/// </summary>
|
||||||
|
public int BlocksPooled
|
||||||
{
|
{
|
||||||
set { dataBlockPoolEnabled = value; }
|
get
|
||||||
get { return dataBlockPoolEnabled; }
|
{
|
||||||
|
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()
|
private PacketPool()
|
||||||
{
|
{
|
||||||
StatsManager.RegisterStat(m_packetsReusedStat);
|
// defaults
|
||||||
StatsManager.RegisterStat(m_blocksReusedStat);
|
RecyclePackets = true;
|
||||||
|
RecycleDataBlocks = true;
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// <returns>Guaranteed to always return a packet, whether from the pool or newly constructed.</returns>
|
||||||
public Packet GetPacket(PacketType type)
|
public Packet GetPacket(PacketType type)
|
||||||
{
|
{
|
||||||
m_packetsReusedStat.Consequent++;
|
PacketsRequested++;
|
||||||
|
|
||||||
Packet packet;
|
Packet packet;
|
||||||
|
|
||||||
if (!packetPoolEnabled)
|
if (!RecyclePackets)
|
||||||
return Packet.BuildPacket(type);
|
return Packet.BuildPacket(type);
|
||||||
|
|
||||||
lock (pool)
|
lock (pool)
|
||||||
|
@ -146,7 +136,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
// m_log.DebugFormat("[PACKETPOOL]: Pulling {0} packet", type);
|
// m_log.DebugFormat("[PACKETPOOL]: Pulling {0} packet", type);
|
||||||
|
|
||||||
// Recycle old packages
|
// Recycle old packages
|
||||||
m_packetsReusedStat.Antecedent++;
|
PacketsReused++;
|
||||||
|
|
||||||
packet = pool[type].Pop();
|
packet = pool[type].Pop();
|
||||||
}
|
}
|
||||||
|
@ -215,7 +205,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
/// <param name="packet"></param>
|
/// <param name="packet"></param>
|
||||||
public void ReturnPacket(Packet packet)
|
public void ReturnPacket(Packet packet)
|
||||||
{
|
{
|
||||||
if (dataBlockPoolEnabled)
|
if (RecycleDataBlocks)
|
||||||
{
|
{
|
||||||
switch (packet.Type)
|
switch (packet.Type)
|
||||||
{
|
{
|
||||||
|
@ -239,7 +229,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packetPoolEnabled)
|
if (RecyclePackets)
|
||||||
{
|
{
|
||||||
switch (packet.Type)
|
switch (packet.Type)
|
||||||
{
|
{
|
||||||
|
@ -277,7 +267,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
{
|
{
|
||||||
lock (DataBlocks)
|
lock (DataBlocks)
|
||||||
{
|
{
|
||||||
m_blocksReusedStat.Consequent++;
|
BlocksRequested++;
|
||||||
|
|
||||||
Stack<Object> s;
|
Stack<Object> s;
|
||||||
|
|
||||||
|
@ -285,7 +275,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
{
|
{
|
||||||
if (s.Count > 0)
|
if (s.Count > 0)
|
||||||
{
|
{
|
||||||
m_blocksReusedStat.Antecedent++;
|
BlocksReused++;
|
||||||
return (T)s.Pop();
|
return (T)s.Pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue