bad merge?

This commit is contained in:
UbitUmarov
2015-09-01 14:54:35 +01:00
406 changed files with 62562 additions and 8067 deletions

View File

@@ -42,6 +42,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public class TokenBucket
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
<<<<<<< HEAD
public string Identifier { get; private set; }
@@ -52,16 +53,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// are defined over this interval.
/// </summary>
protected const Int32 m_ticksPerQuantum = 1000;
=======
private static Int32 m_counter = 0;
// private Int32 m_identifier;
protected const float m_timeScale = 1e-3f;
>>>>>>> avn/ubitvar
/// <summary>
/// This is the number of quantums worth of packets that can
/// be accommodated during a burst
/// This is the number of m_minimumDripRate bytes
/// allowed in a burst
/// roughtly, with this settings, the maximum time system will take
/// to recheck a bucket in ms
///
/// </summary>
protected const Double m_quantumsPerBurst = 1.5;
protected const float m_quantumsPerBurst = 5;
/// <summary>
/// </summary>
<<<<<<< HEAD
protected const Int32 m_minimumDripRate = LLUDPServer.MTU;
=======
protected const float m_minimumDripRate = 1400;
>>>>>>> avn/ubitvar
/// <summary>Time of the last drip, in system ticks</summary>
protected Int32 m_lastDrip;
@@ -70,12 +85,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// The number of bytes that can be sent at this moment. This is the
/// current number of tokens in the bucket
/// </summary>
protected Int64 m_tokenCount;
protected float m_tokenCount;
/// <summary>
/// Map of children buckets and their requested maximum burst rate
/// </summary>
<<<<<<< HEAD
protected Dictionary<TokenBucket,Int64> m_children = new Dictionary<TokenBucket,Int64>();
=======
protected Dictionary<TokenBucket, float> m_children = new Dictionary<TokenBucket, float>();
#region Properties
>>>>>>> avn/ubitvar
/// <summary>
/// The parent bucket of this bucket, or null if this bucket has no
@@ -85,25 +106,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public TokenBucket Parent { get; protected set; }
/// <summary>
/// Maximum burst rate in bytes per second. This is the maximum number
/// This is the maximum number
/// of tokens that can accumulate in the bucket at any one time. This
/// also sets the total request for leaf nodes
/// </summary>
protected Int64 m_burstRate;
public Int64 RequestedBurstRate
protected float m_burst;
public float RequestedBurst
{
get { return m_burstRate; }
set { m_burstRate = (value < 0 ? 0 : value); }
get { return m_burst; }
set {
float rate = (value < 0 ? 0 : value);
if (rate < m_minimumDripRate)
rate = m_minimumDripRate;
else if (rate > m_minimumDripRate * m_quantumsPerBurst)
rate = m_minimumDripRate * m_quantumsPerBurst;
m_burst = rate;
}
}
public Int64 BurstRate
public float Burst
{
get {
double rate = RequestedBurstRate * BurstRateModifier();
if (rate < m_minimumDripRate * m_quantumsPerBurst)
rate = m_minimumDripRate * m_quantumsPerBurst;
return (Int64) rate;
float rate = RequestedBurst * BurstModifier();
if (rate < m_minimumDripRate)
rate = m_minimumDripRate;
return (float)rate;
}
}
@@ -115,6 +143,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// Can never be above MaxDripRate.
/// Tokens are added to the bucket at any time
/// <seealso cref="RemoveTokens"/> is called, at the granularity of
<<<<<<< HEAD
/// the system tick interval (typically around 15-22ms)
/// FIXME: It is extremely confusing to be able to set a RequestedDripRate of 0 and then receive a positive
/// number on get if TotalDripRequest is set. This also stops us being able to retrieve the fact that
@@ -168,12 +197,36 @@ namespace OpenSim.Region.ClientStack.LindenUDP
rate = (double)RequestedDripRate * Parent.DripRateModifier();
}
=======
/// the system tick interval (typically around 15-22ms)</remarks>
protected float m_dripRate;
public virtual float RequestedDripRate
{
get { return (m_dripRate == 0 ? m_totalDripRequest : m_dripRate); }
set {
m_dripRate = (value < 0 ? 0 : value);
m_totalDripRequest = m_dripRate;
if (m_parent != null)
m_parent.RegisterRequest(this,m_dripRate);
}
}
public virtual float DripRate
{
get {
float rate = Math.Min(RequestedDripRate,TotalDripRequest);
if (m_parent == null)
return rate;
rate *= m_parent.DripRateModifier();
>>>>>>> avn/ubitvar
if (rate < m_minimumDripRate)
rate = m_minimumDripRate;
else if (MaxDripRate > 0 && rate > MaxDripRate)
rate = MaxDripRate;
return (Int64)rate;
return (float)rate;
}
}
protected Int64 m_dripRate;
@@ -186,7 +239,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <summary>
/// The current total of the requested maximum burst rates of children buckets.
/// </summary>
<<<<<<< HEAD
public Int64 TotalDripRequest { get; protected set; }
=======
protected float m_totalDripRequest;
public float TotalDripRequest
{
get { return m_totalDripRequest; }
set { m_totalDripRequest = value; }
}
#endregion Properties
#region Constructor
>>>>>>> avn/ubitvar
/// <summary>
/// Default constructor
@@ -194,18 +260,34 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <param name="identifier">Identifier for this token bucket</param>
/// <param name="parent">Parent bucket if this is a child bucket, or
/// null if this is a root bucket</param>
<<<<<<< HEAD
/// <param name="requestedDripRate">
/// Requested rate that the bucket fills, in bytes per
/// second. If zero, the bucket always remains full.
/// </param>
public TokenBucket(string identifier, TokenBucket parent, Int64 requestedDripRate, Int64 maxDripRate)
=======
/// <param name="maxBurst">Maximum size of the bucket in bytes, or
/// zero if this bucket has no maximum capacity</param>
/// <param name="dripRate">Rate that the bucket fills, in bytes per
/// second. If zero, the bucket always remains full</param>
public TokenBucket(TokenBucket parent, float dripRate, float MaxBurst)
>>>>>>> avn/ubitvar
{
Identifier = identifier;
Parent = parent;
<<<<<<< HEAD
RequestedDripRate = requestedDripRate;
MaxDripRate = maxDripRate;
m_lastDrip = Util.EnvironmentTickCount();
=======
RequestedDripRate = dripRate;
RequestedBurst = MaxBurst;
// TotalDripRequest = dripRate; // this will be overwritten when a child node registers
// MaxBurst = (Int64)((double)dripRate * m_quantumsPerBurst);
m_lastDrip = Util.EnvironmentTickCount() + 100000;
>>>>>>> avn/ubitvar
}
/// <summary>
@@ -215,8 +297,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// hierarchy. However, if any of the parents is over-booked, then
/// the modifier will be less than 1.
/// </summary>
protected double DripRateModifier()
protected float DripRateModifier()
{
<<<<<<< HEAD
Int64 driprate = DripRate;
double modifier = driprate >= TotalDripRequest ? 1.0 : (double)driprate / (double)TotalDripRequest;
@@ -226,11 +309,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// driprate, TotalDripRequest, modifier, Identifier);
return modifier;
=======
float driprate = DripRate;
return driprate >= TotalDripRequest ? 1.0f : driprate / TotalDripRequest;
>>>>>>> avn/ubitvar
}
/// <summary>
/// </summary>
protected double BurstRateModifier()
protected float BurstModifier()
{
// for now... burst rate is always m_quantumsPerBurst (constant)
// larger than drip rate so the ratio of burst requests is the
@@ -242,15 +329,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// Register drip rate requested by a child of this throttle. Pass the
/// changes up the hierarchy.
/// </summary>
public void RegisterRequest(TokenBucket child, Int64 request)
public void RegisterRequest(TokenBucket child, float request)
{
lock (m_children)
{
m_children[child] = request;
<<<<<<< HEAD
TotalDripRequest = 0;
foreach (KeyValuePair<TokenBucket, Int64> cref in m_children)
TotalDripRequest += cref.Value;
=======
m_totalDripRequest = 0;
foreach (KeyValuePair<TokenBucket, float> cref in m_children)
m_totalDripRequest += cref.Value;
>>>>>>> avn/ubitvar
}
// Pass the new values up to the parent
@@ -277,9 +370,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{
m_children.Remove(child);
<<<<<<< HEAD
TotalDripRequest = 0;
foreach (KeyValuePair<TokenBucket, Int64> cref in m_children)
TotalDripRequest += cref.Value;
=======
m_totalDripRequest = 0;
foreach (KeyValuePair<TokenBucket, float> cref in m_children)
m_totalDripRequest += cref.Value;
>>>>>>> avn/ubitvar
}
// Pass the new values up to the parent
@@ -293,7 +392,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <param name="amount">Number of tokens to remove from the bucket</param>
/// <returns>True if the requested number of tokens were removed from
/// the bucket, otherwise false</returns>
public bool RemoveTokens(Int64 amount)
public bool RemoveTokens(int amount)
{
// Deposit tokens for this interval
Drip();
@@ -310,19 +409,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return false;
}
/// <summary>
/// Deposit tokens into the bucket from a child bucket that did
/// not use all of its available tokens
/// </summary>
protected void Deposit(Int64 count)
public int GetCatBytesCanSend(int timeMS)
{
m_tokenCount += count;
// Deposit the overflow in the parent bucket, this is how we share
// unused bandwidth
Int64 burstrate = BurstRate;
if (m_tokenCount > burstrate)
m_tokenCount = burstrate;
// return (int)(m_tokenCount + timeMS * m_dripRate * 1e-3);
return (int)(timeMS * m_dripRate * 1e-3);
}
/// <summary>
@@ -341,17 +431,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return;
}
// Determine the interval over which we are adding tokens, never add
// more than a single quantum of tokens
Int32 deltaMS = Math.Min(Util.EnvironmentTickCountSubtract(m_lastDrip), m_ticksPerQuantum);
m_lastDrip = Util.EnvironmentTickCount();
Int32 now = Util.EnvironmentTickCount();
Int32 deltaMS = now - m_lastDrip;
m_lastDrip = now;
// This can be 0 in the very unusual case that the timer wrapped
// It can be 0 if we try add tokens at a sub-tick rate
if (deltaMS <= 0)
return;
Deposit(deltaMS * DripRate / m_ticksPerQuantum);
m_tokenCount += deltaMS * DripRate * m_timeScale;
float burst = Burst;
if (m_tokenCount > burst)
m_tokenCount = burst;
}
}
@@ -362,6 +453,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public bool AdaptiveEnabled { get; set; }
/// <summary>
<<<<<<< HEAD
/// Target drip rate for this bucket.
/// </summary>
/// <remarks>Usually set by the client. If adaptive is enabled then throttles will increase until we reach this.</remarks>
@@ -371,6 +463,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP
set
{
m_targetDripRate = Math.Max(value, m_minimumFlow);
=======
/// The minimum rate for flow control. Minimum drip rate is one
/// packet per second.
/// </summary>
protected const float m_minimumFlow = 50000;
// <summary>
// The maximum rate for flow control. Drip rate can never be
// greater than this.
// </summary>
protected float m_maxDripRate = 0;
public float MaxDripRate
{
get { return (m_maxDripRate == 0 ? m_totalDripRequest : m_maxDripRate); }
set
{
m_maxDripRate = (value == 0 ? m_totalDripRequest : Math.Max(value, m_minimumFlow));
>>>>>>> avn/ubitvar
}
}
protected Int64 m_targetDripRate;
@@ -378,9 +490,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// <summary>
// Adjust drip rate in response to network conditions.
// </summary>
public virtual Int64 AdjustedDripRate
public virtual float AdjustedDripRate
{
get { return m_dripRate; }
<<<<<<< HEAD
set
{
m_dripRate = OpenSim.Framework.Util.Clamp<Int64>(value, m_minimumFlow, TargetDripRate);
@@ -388,6 +501,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (Parent != null)
Parent.RegisterRequest(this, m_dripRate);
=======
set {
m_dripRate = OpenSim.Framework.Util.Clamp<float>(value,m_minimumFlow,MaxDripRate);
if (m_parent != null)
m_parent.RegisterRequest(this,m_dripRate);
>>>>>>> avn/ubitvar
}
}
@@ -396,6 +516,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// </summary>
protected Int64 m_minimumFlow = 32000;
<<<<<<< HEAD
/// <summary>
/// Constructor for the AdaptiveTokenBucket class
/// <param name="identifier">Unique identifier for the client</param>
@@ -416,6 +537,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP
TargetDripRate = m_minimumFlow;
AdjustedDripRate = m_minimumFlow;
}
=======
// <summary>
//
// </summary>
public AdaptiveTokenBucket(TokenBucket parent, float maxDripRate,float maxBurst, bool enabled)
: base(parent, maxDripRate,maxBurst)
{
m_enabled = enabled;
MaxDripRate = maxDripRate;
if (enabled)
AdjustedDripRate = m_maxDripRate * .5f;
else
AdjustedDripRate = m_maxDripRate;
>>>>>>> avn/ubitvar
}
/// <summary>
@@ -461,4 +598,4 @@ namespace OpenSim.Region.ClientStack.LindenUDP
AdjustedDripRate = m_minimumFlow;
}
}
}
}