*needs testing, not that good* change throttles math using floats and not

int64, etc. Limite brust bytes to the total rate client requested times a
look ahead estimation time, Avoid queues starvation with updates waiting...
avinationmerge
UbitUmarov 2014-09-02 15:48:59 +01:00
parent 18de5c8a2d
commit 50433e089b
4 changed files with 112 additions and 125 deletions

View File

@ -144,8 +144,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
get { return m_throttleClient; } get { return m_throttleClient; }
} }
/// <summary>Throttle bucket for this agent's connection</summary>
private readonly TokenBucket m_throttleCategory;
/// <summary>Throttle buckets for each packet category</summary> /// <summary>Throttle buckets for each packet category</summary>
private readonly TokenBucket[] m_throttleCategories; private readonly TokenBucket[] m_throttleCategories;
/// <summary>Outgoing queues for throttled packets</summary> /// <summary>Outgoing queues for throttled packets</summary>
@ -163,6 +161,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private int m_maxRTO = 60000; private int m_maxRTO = 60000;
public bool m_deliverPackets = true; public bool m_deliverPackets = true;
private float m_burstTime;
public int m_lastStartpingTimeMS; public int m_lastStartpingTimeMS;
public int m_pingMS; public int m_pingMS;
@ -216,17 +216,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (maxRTO != 0) if (maxRTO != 0)
m_maxRTO = maxRTO; m_maxRTO = maxRTO;
m_burstTime = rates.BrustTime;
float m_burst = rates.ClientMaxRate * m_burstTime;
// Create a token bucket throttle for this client that has the scene token bucket as a parent // Create a token bucket throttle for this client that has the scene token bucket as a parent
m_throttleClient = new AdaptiveTokenBucket(parentThrottle, rates.Total, rates.AdaptiveThrottlesEnabled); m_throttleClient = new AdaptiveTokenBucket(parentThrottle, rates.ClientMaxRate, m_burst, rates.AdaptiveThrottlesEnabled);
// Create a token bucket throttle for the total categary with the client bucket as a throttle
m_throttleCategory = new TokenBucket(m_throttleClient, 0);
// Create an array of token buckets for this clients different throttle categories // Create an array of token buckets for this clients different throttle categories
m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT]; m_throttleCategories = new TokenBucket[THROTTLE_CATEGORY_COUNT];
m_cannibalrate = rates.CannibalizeTextureRate; m_cannibalrate = rates.CannibalizeTextureRate;
long totalrate = 0; m_burst = rates.Total * rates.BrustTime;
long catrate = 0;
for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++) for (int i = 0; i < THROTTLE_CATEGORY_COUNT; i++)
{ {
@ -235,13 +235,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// Initialize the packet outboxes, where packets sit while they are waiting for tokens // Initialize the packet outboxes, where packets sit while they are waiting for tokens
m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>(); m_packetOutboxes[i] = new DoubleLocklessQueue<OutgoingPacket>();
// Initialize the token buckets that control the throttling for each category // Initialize the token buckets that control the throttling for each category
catrate = rates.GetRate(type); m_throttleCategories[i] = new TokenBucket(m_throttleClient, rates.GetRate(type), m_burst);
totalrate += catrate;
m_throttleCategories[i] = new TokenBucket(m_throttleCategory, catrate);
} }
m_throttleCategory.RequestedDripRate = totalrate;
// Default the retransmission timeout to one second // Default the retransmission timeout to one second
RTO = m_defaultRTO; RTO = m_defaultRTO;
@ -285,7 +281,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_info.taskThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Task].DripRate; m_info.taskThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Task].DripRate;
m_info.assetThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Asset].DripRate; m_info.assetThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Asset].DripRate;
m_info.textureThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Texture].DripRate; m_info.textureThrottle = (int)m_throttleCategories[(int)ThrottleOutPacketType.Texture].DripRate;
m_info.totalThrottle = (int)m_throttleCategory.DripRate; m_info.totalThrottle = (int)m_throttleClient.DripRate;
return m_info; return m_info;
} }
@ -373,6 +369,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// Make sure none of the throttles are set below our packet MTU, // Make sure none of the throttles are set below our packet MTU,
// otherwise a throttle could become permanently clogged // otherwise a throttle could become permanently clogged
/* not using floats
resend = Math.Max(resend, LLUDPServer.MTU); resend = Math.Max(resend, LLUDPServer.MTU);
land = Math.Max(land, LLUDPServer.MTU); land = Math.Max(land, LLUDPServer.MTU);
wind = Math.Max(wind, LLUDPServer.MTU); wind = Math.Max(wind, LLUDPServer.MTU);
@ -380,6 +378,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
task = Math.Max(task, LLUDPServer.MTU); task = Math.Max(task, LLUDPServer.MTU);
texture = Math.Max(texture, LLUDPServer.MTU); texture = Math.Max(texture, LLUDPServer.MTU);
asset = Math.Max(asset, LLUDPServer.MTU); asset = Math.Max(asset, LLUDPServer.MTU);
*/
// Since most textures are now delivered through http, make it possible // Since most textures are now delivered through http, make it possible
// to cannibalize some of the bw from the texture throttle to use for // to cannibalize some of the bw from the texture throttle to use for
@ -388,7 +387,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
texture = (int)((1 - m_cannibalrate) * texture); texture = (int)((1 - m_cannibalrate) * texture);
int total = resend + land + wind + cloud + task + texture + asset; int total = resend + land + wind + cloud + task + texture + asset;
float m_burst = total * m_burstTime;
//m_log.DebugFormat("[LLUDPCLIENT]: {0} is setting throttles. Resend={1}, Land={2}, Wind={3}, Cloud={4}, Task={5}, Texture={6}, Asset={7}, Total={8}", //m_log.DebugFormat("[LLUDPCLIENT]: {0} is setting throttles. Resend={1}, Land={2}, Wind={3}, Cloud={4}, Task={5}, Texture={6}, Asset={7}, Total={8}",
// AgentID, resend, land, wind, cloud, task, texture, asset, total); // AgentID, resend, land, wind, cloud, task, texture, asset, total);
@ -397,26 +398,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP
bucket = m_throttleCategories[(int)ThrottleOutPacketType.Resend]; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Resend];
bucket.RequestedDripRate = resend; bucket.RequestedDripRate = resend;
bucket.RequestedBurst = m_burst;
bucket = m_throttleCategories[(int)ThrottleOutPacketType.Land]; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Land];
bucket.RequestedDripRate = land; bucket.RequestedDripRate = land;
bucket.RequestedBurst = m_burst;
bucket = m_throttleCategories[(int)ThrottleOutPacketType.Wind]; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Wind];
bucket.RequestedDripRate = wind; bucket.RequestedDripRate = wind;
bucket.RequestedBurst = m_burst;
bucket = m_throttleCategories[(int)ThrottleOutPacketType.Cloud]; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Cloud];
bucket.RequestedDripRate = cloud; bucket.RequestedDripRate = cloud;
bucket.RequestedBurst = m_burst;
bucket = m_throttleCategories[(int)ThrottleOutPacketType.Asset]; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Asset];
bucket.RequestedDripRate = asset; bucket.RequestedDripRate = asset;
bucket.RequestedBurst = m_burst;
bucket = m_throttleCategories[(int)ThrottleOutPacketType.Task]; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Task];
bucket.RequestedDripRate = task; bucket.RequestedDripRate = task;
bucket.RequestedBurst = m_burst;
bucket = m_throttleCategories[(int)ThrottleOutPacketType.Texture]; bucket = m_throttleCategories[(int)ThrottleOutPacketType.Texture];
bucket.RequestedDripRate = texture; bucket.RequestedDripRate = texture;
bucket.RequestedBurst = m_burst;
m_throttleCategory.RequestedDripRate = total;
// Reset the packed throttles cached data // Reset the packed throttles cached data
m_packedThrottles = null; m_packedThrottles = null;
@ -465,10 +471,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public int GetCatBytesCanSend(ThrottleOutPacketType cat, int timeMS) public int GetCatBytesCanSend(ThrottleOutPacketType cat, int timeMS)
{ {
TokenBucket bucket = m_throttleCategories[(int)cat]; int icat = (int)cat;
int bytes = timeMS * (int)(bucket.RequestedDripRate / 1000); if (icat > 0 && icat < THROTTLE_CATEGORY_COUNT)
bytes += (int)bucket.CurrentTokenCount(); {
return bytes; TokenBucket bucket = m_throttleCategories[icat];
return bucket.GetCatBytesCanSend(timeMS);
}
else
return 0;
} }
/// <summary> /// <summary>
@ -572,6 +582,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_udpServer.SendPacketFinal(nextPacket); m_udpServer.SendPacketFinal(nextPacket);
m_nextPackets[i] = null; m_nextPackets[i] = null;
packetSent = true; packetSent = true;
if (m_packetOutboxes[i].Count < 5)
emptyCategories |= CategoryToFlag(i);
} }
} }
else else
@ -599,6 +612,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// Send the packet // Send the packet
m_udpServer.SendPacketFinal(packet); m_udpServer.SendPacketFinal(packet);
packetSent = true; packetSent = true;
if (queue.Count < 5)
emptyCategories |= CategoryToFlag(i);
} }
else else
{ {
@ -606,11 +622,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_nextPackets[i] = packet; m_nextPackets[i] = packet;
} }
// If the queue is empty after this dequeue, fire the queue
// empty callback now so it has a chance to fill before we
// get back here
if (queue.Count == 0)
emptyCategories |= CategoryToFlag(i);
} }
else else
{ {

View File

@ -449,7 +449,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
#endregion BinaryStats #endregion BinaryStats
m_throttle = new TokenBucket(null, sceneThrottleBps); m_throttle = new TokenBucket(null, sceneThrottleBps, sceneThrottleBps * 10e-3f);
ThrottleRates = new ThrottleRates(configSource); ThrottleRates = new ThrottleRates(configSource);
Random rnd = new Random(Util.EnvironmentTickCount()); Random rnd = new Random(Util.EnvironmentTickCount());

View File

@ -62,6 +62,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <summary>Amount of the texture throttle to steal for the task throttle</summary> /// <summary>Amount of the texture throttle to steal for the task throttle</summary>
public double CannibalizeTextureRate; public double CannibalizeTextureRate;
public int ClientMaxRate;
public float BrustTime;
/// <summary> /// <summary>
/// Default constructor /// Default constructor
/// </summary> /// </summary>
@ -80,8 +83,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
Texture = throttleConfig.GetInt("texture_default", 18500); Texture = throttleConfig.GetInt("texture_default", 18500);
Asset = throttleConfig.GetInt("asset_default", 10500); Asset = throttleConfig.GetInt("asset_default", 10500);
// 2500000 bps max Total = Resend + Land + Wind + Cloud + Task + Texture + Asset;
Total = throttleConfig.GetInt("client_throttle_max_bps",312500); // 3000000 bps default max
ClientMaxRate = throttleConfig.GetInt("client_throttle_max_bps", 375000);
if (ClientMaxRate > 1000000)
ClientMaxRate = 1000000; // no more than 8Mbps
BrustTime = (float)throttleConfig.GetInt("client_throttle_burtsTimeMS", 10);
BrustTime *= 1e-3f;
AdaptiveThrottlesEnabled = throttleConfig.GetBoolean("enable_adaptive_throttles", false); AdaptiveThrottlesEnabled = throttleConfig.GetBoolean("enable_adaptive_throttles", false);

View File

@ -44,13 +44,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static Int32 m_counter = 0; private static Int32 m_counter = 0;
// private Int32 m_identifier; // private Int32 m_identifier;
/// <summary> protected const float m_timeScale = 1e-3f;
/// Number of ticks (ms) per quantum, drip rate and max burst
/// are defined over this interval.
/// </summary>
protected const Int32 m_ticksPerQuantum = 1000;
/// <summary> /// <summary>
/// This is the number of m_minimumDripRate bytes /// This is the number of m_minimumDripRate bytes
@ -59,11 +55,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// to recheck a bucket in ms /// to recheck a bucket in ms
/// ///
/// </summary> /// </summary>
protected const Double m_quantumsPerBurst = 5; protected const float m_quantumsPerBurst = 5;
/// <summary> /// <summary>
/// </summary> /// </summary>
protected const Int32 m_minimumDripRate = 1400; protected const float m_minimumDripRate = 1400;
/// <summary>Time of the last drip, in system ticks</summary> /// <summary>Time of the last drip, in system ticks</summary>
protected Int32 m_lastDrip; protected Int32 m_lastDrip;
@ -72,12 +68,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// The number of bytes that can be sent at this moment. This is the /// The number of bytes that can be sent at this moment. This is the
/// current number of tokens in the bucket /// current number of tokens in the bucket
/// </summary> /// </summary>
protected Int64 m_tokenCount; protected float m_tokenCount;
/// <summary> /// <summary>
/// Map of children buckets and their requested maximum burst rate /// Map of children buckets and their requested maximum burst rate
/// </summary> /// </summary>
protected Dictionary<TokenBucket,Int64> m_children = new Dictionary<TokenBucket,Int64>(); protected Dictionary<TokenBucket, float> m_children = new Dictionary<TokenBucket, float>();
#region Properties #region Properties
@ -97,33 +93,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// This is the maximum number /// This is the maximum number
/// of tokens that can accumulate in the bucket at any one time. This /// of tokens that can accumulate in the bucket at any one time. This
/// also sets the total request for leaf nodes /// also sets the total request for leaf nodes
/// this is not a rate.
/// </summary> /// </summary>
protected Int64 m_burstRate; protected float m_burst;
public Int64 RequestedBurstRate public float RequestedBurst
{ {
get { return m_burstRate; } get { return m_burst; }
set { set {
double rate = (value < 0 ? 0 : value); float rate = (value < 0 ? 0 : value);
if (rate < m_minimumDripRate) if (rate < m_minimumDripRate)
rate = m_minimumDripRate; rate = m_minimumDripRate;
else if (rate > m_minimumDripRate * m_quantumsPerBurst) else if (rate > m_minimumDripRate * m_quantumsPerBurst)
rate = m_minimumDripRate * m_quantumsPerBurst; rate = m_minimumDripRate * m_quantumsPerBurst;
m_burstRate = (Int64)rate; m_burst = rate;
} }
} }
public Int64 BurstRate public float Burst
{ {
get { get {
double rate = RequestedBurstRate * BurstRateModifier(); float rate = RequestedBurst * BurstModifier();
if (rate < m_minimumDripRate) if (rate < m_minimumDripRate)
rate = m_minimumDripRate; rate = m_minimumDripRate;
else if (rate > m_minimumDripRate * m_quantumsPerBurst) return (float)rate;
rate = m_minimumDripRate * m_quantumsPerBurst;
return (Int64) rate;
} }
} }
@ -134,40 +126,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <remarks>Tokens are added to the bucket any time /// <remarks>Tokens are added to the bucket any time
/// <seealso cref="RemoveTokens"/> is called, at the granularity of /// <seealso cref="RemoveTokens"/> is called, at the granularity of
/// the system tick interval (typically around 15-22ms)</remarks> /// the system tick interval (typically around 15-22ms)</remarks>
protected Int64 m_dripRate; protected float m_dripRate;
public virtual Int64 RequestedDripRate public virtual float RequestedDripRate
{ {
get { return (m_dripRate == 0 ? m_totalDripRequest : m_dripRate); } get { return (m_dripRate == 0 ? m_totalDripRequest : m_dripRate); }
set { set {
m_dripRate = (value < 0 ? 0 : value); m_dripRate = (value < 0 ? 0 : value);
m_totalDripRequest = m_dripRate; m_totalDripRequest = m_dripRate;
double rate = m_dripRate;
if (rate > m_minimumDripRate * m_quantumsPerBurst)
rate = m_minimumDripRate * m_quantumsPerBurst;
else if (rate < m_minimumDripRate)
rate = m_minimumDripRate;
m_burstRate = (Int64)rate;
m_tokenCount = 0;
if (m_parent != null) if (m_parent != null)
m_parent.RegisterRequest(this,m_dripRate); m_parent.RegisterRequest(this,m_dripRate);
} }
} }
public virtual Int64 DripRate public virtual float DripRate
{ {
get { get {
float rate = Math.Min(RequestedDripRate,TotalDripRequest);
if (m_parent == null) if (m_parent == null)
return Math.Min(RequestedDripRate,TotalDripRequest); return rate;
double rate = (double)RequestedDripRate * m_parent.DripRateModifier(); rate *= m_parent.DripRateModifier();
if (rate < m_minimumDripRate) if (rate < m_minimumDripRate)
rate = m_minimumDripRate; rate = m_minimumDripRate;
return (Int64)rate; return (float)rate;
} }
} }
@ -175,8 +158,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// The current total of the requested maximum burst rates of /// The current total of the requested maximum burst rates of
/// this bucket's children buckets. /// this bucket's children buckets.
/// </summary> /// </summary>
protected Int64 m_totalDripRequest; protected float m_totalDripRequest;
public Int64 TotalDripRequest public float TotalDripRequest
{ {
get { return m_totalDripRequest; } get { return m_totalDripRequest; }
set { m_totalDripRequest = value; } set { m_totalDripRequest = value; }
@ -195,13 +178,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// zero if this bucket has no maximum capacity</param> /// zero if this bucket has no maximum capacity</param>
/// <param name="dripRate">Rate that the bucket fills, in bytes per /// <param name="dripRate">Rate that the bucket fills, in bytes per
/// second. If zero, the bucket always remains full</param> /// second. If zero, the bucket always remains full</param>
public TokenBucket(TokenBucket parent, Int64 dripRate) public TokenBucket(TokenBucket parent, float dripRate, float MaxBurst)
{ {
// m_identifier = m_counter++; // m_identifier = m_counter++;
m_counter++; m_counter++;
Parent = parent; Parent = parent;
RequestedDripRate = dripRate; RequestedDripRate = dripRate;
RequestedBurst = MaxBurst;
// TotalDripRequest = dripRate; // this will be overwritten when a child node registers // TotalDripRequest = dripRate; // this will be overwritten when a child node registers
// MaxBurst = (Int64)((double)dripRate * m_quantumsPerBurst); // MaxBurst = (Int64)((double)dripRate * m_quantumsPerBurst);
m_lastDrip = Util.EnvironmentTickCount() + 100000; m_lastDrip = Util.EnvironmentTickCount() + 100000;
@ -216,15 +200,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// hierarchy. However, if any of the parents is over-booked, then /// hierarchy. However, if any of the parents is over-booked, then
/// the modifier will be less than 1. /// the modifier will be less than 1.
/// </summary> /// </summary>
protected double DripRateModifier() protected float DripRateModifier()
{ {
Int64 driprate = DripRate; float driprate = DripRate;
return driprate >= TotalDripRequest ? 1.0 : (double)driprate / (double)TotalDripRequest; return driprate >= TotalDripRequest ? 1.0f : driprate / TotalDripRequest;
} }
/// <summary> /// <summary>
/// </summary> /// </summary>
protected double BurstRateModifier() protected float BurstModifier()
{ {
// for now... burst rate is always m_quantumsPerBurst (constant) // for now... burst rate is always m_quantumsPerBurst (constant)
// larger than drip rate so the ratio of burst requests is the // larger than drip rate so the ratio of burst requests is the
@ -236,7 +220,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// Register drip rate requested by a child of this throttle. Pass the /// Register drip rate requested by a child of this throttle. Pass the
/// changes up the hierarchy. /// changes up the hierarchy.
/// </summary> /// </summary>
public void RegisterRequest(TokenBucket child, Int64 request) public void RegisterRequest(TokenBucket child, float request)
{ {
lock (m_children) lock (m_children)
{ {
@ -244,7 +228,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// m_totalDripRequest = m_children.Values.Sum(); // m_totalDripRequest = m_children.Values.Sum();
m_totalDripRequest = 0; m_totalDripRequest = 0;
foreach (KeyValuePair<TokenBucket, Int64> cref in m_children) foreach (KeyValuePair<TokenBucket, float> cref in m_children)
m_totalDripRequest += cref.Value; m_totalDripRequest += cref.Value;
} }
@ -265,7 +249,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// m_totalDripRequest = m_children.Values.Sum(); // m_totalDripRequest = m_children.Values.Sum();
m_totalDripRequest = 0; m_totalDripRequest = 0;
foreach (KeyValuePair<TokenBucket, Int64> cref in m_children) foreach (KeyValuePair<TokenBucket, float> cref in m_children)
m_totalDripRequest += cref.Value; m_totalDripRequest += cref.Value;
} }
@ -281,7 +265,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <param name="amount">Number of tokens to remove from the bucket</param> /// <param name="amount">Number of tokens to remove from the bucket</param>
/// <returns>True if the requested number of tokens were removed from /// <returns>True if the requested number of tokens were removed from
/// the bucket, otherwise false</returns> /// the bucket, otherwise false</returns>
public bool RemoveTokens(Int64 amount) public bool RemoveTokens(int amount)
{ {
// Deposit tokens for this interval // Deposit tokens for this interval
Drip(); Drip();
@ -298,24 +282,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return false; return false;
} }
public long CurrentTokenCount() public int GetCatBytesCanSend(int timeMS)
{ {
return m_tokenCount; // return (int)(m_tokenCount + timeMS * m_dripRate * 1e-3);
} return (int)(timeMS * m_dripRate * 1e-3);
/// <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)
{
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;
} }
/// <summary> /// <summary>
@ -334,12 +304,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return; return;
} }
// Determine the interval over which we are adding tokens, never add Int32 deltaMS = Util.EnvironmentTickCountSubtract(m_lastDrip);
// more than a single quantum of tokens
// No... add no more than the estimated time between checks
Int32 deltaMS = Math.Min(Util.EnvironmentTickCountSubtract(m_lastDrip), m_ticksPerQuantum);
m_lastDrip = Util.EnvironmentTickCount(); m_lastDrip = Util.EnvironmentTickCount();
// This can be 0 in the very unusual case that the timer wrapped // This can be 0 in the very unusual case that the timer wrapped
@ -347,7 +312,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (deltaMS <= 0) if (deltaMS <= 0)
return; return;
Deposit(deltaMS * DripRate / m_ticksPerQuantum); m_tokenCount += deltaMS * DripRate * m_timeScale;
float burst = Burst;
if (m_tokenCount > burst)
m_tokenCount = burst;
} }
} }
@ -357,20 +326,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <summary> /// <summary>
/// The minimum rate for flow control. Minimum drip rate is one /// The minimum rate for flow control. Minimum drip rate is one
/// packet per second. Open the throttle to 15 packets per second /// packet per second.
/// or about 160kbps.
/// </summary> /// </summary>
protected const Int64 m_minimumFlow = m_minimumDripRate;
protected const float m_minimumFlow = 50000;
// <summary> // <summary>
// The maximum rate for flow control. Drip rate can never be // The maximum rate for flow control. Drip rate can never be
// greater than this. // greater than this.
// </summary> // </summary>
protected Int64 m_maxDripRate = 0;
protected Int64 MaxDripRate protected float m_maxDripRate = 0;
public float MaxDripRate
{ {
get { return (m_maxDripRate == 0 ? m_totalDripRequest : m_maxDripRate); } get { return (m_maxDripRate == 0 ? m_totalDripRequest : m_maxDripRate); }
set { m_maxDripRate = (value == 0 ? 0 : Math.Max(value,m_minimumFlow)); } set
{
m_maxDripRate = (value == 0 ? m_totalDripRequest : Math.Max(value, m_minimumFlow));
}
} }
private bool m_enabled = false; private bool m_enabled = false;
@ -378,18 +351,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// <summary> // <summary>
// //
// </summary> // </summary>
public virtual Int64 AdjustedDripRate public virtual float AdjustedDripRate
{ {
get { return m_dripRate; } get { return m_dripRate; }
set { set {
m_dripRate = OpenSim.Framework.Util.Clamp<Int64>(value,m_minimumFlow,MaxDripRate); m_dripRate = OpenSim.Framework.Util.Clamp<float>(value,m_minimumFlow,MaxDripRate);
double rate = m_dripRate;
if (rate > m_minimumDripRate * m_quantumsPerBurst)
rate = m_minimumDripRate * m_quantumsPerBurst;
else if (rate < m_minimumDripRate)
rate = m_minimumDripRate;
m_burstRate = (Int64)rate;
if (m_parent != null) if (m_parent != null)
m_parent.RegisterRequest(this,m_dripRate); m_parent.RegisterRequest(this,m_dripRate);
@ -399,16 +365,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// <summary> // <summary>
// //
// </summary> // </summary>
public AdaptiveTokenBucket(TokenBucket parent, Int64 maxDripRate, bool enabled) : base(parent,maxDripRate) public AdaptiveTokenBucket(TokenBucket parent, float maxDripRate,float maxBurst, bool enabled)
: base(parent, maxDripRate,maxBurst)
{ {
m_enabled = enabled; m_enabled = enabled;
MaxDripRate = maxDripRate;
if (m_enabled) if (enabled)
{ AdjustedDripRate = m_maxDripRate * .5f;
// m_log.DebugFormat("[TOKENBUCKET] Adaptive throttle enabled"); else
MaxDripRate = maxDripRate; AdjustedDripRate = m_maxDripRate;
AdjustedDripRate = m_minimumFlow;
}
} }
// <summary> // <summary>