aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs41
1 files changed, 14 insertions, 27 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs b/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs
index 1bf05a3..06864c0 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/TokenBucket.cs
@@ -45,15 +45,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
45 45
46 private static Int32 m_counter = 0; 46 private static Int32 m_counter = 0;
47 47
48 protected const float m_timeScale = 1e-3f; 48 /// <summary>
49
50 /// <summary>
51 /// minimum recovery rate, ie bandwith 49 /// minimum recovery rate, ie bandwith
52 /// </summary> 50 /// </summary>
53 protected const float MINDRIPRATE = 500; 51 protected const float MINDRIPRATE = 500;
54 52
55 // minimum and maximim burst size, ie max number of bytes token can have 53 // maximim burst size, ie max number of bytes token can have
56 protected const float MINBURST = 1500; // can't be less than one MTU or it will block
57 protected const float MAXBURST = 7500; 54 protected const float MAXBURST = 7500;
58 55
59 /// <summary>Time of the last drip</summary> 56 /// <summary>Time of the last drip</summary>
@@ -103,9 +100,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
103 get { return m_burst; } 100 get { return m_burst; }
104 set { 101 set {
105 float rate = (value < 0 ? 0 : value); 102 float rate = (value < 0 ? 0 : value);
106 if (rate < MINBURST) 103 if (rate > MAXBURST)
107 rate = MINBURST;
108 else if (rate > MAXBURST)
109 rate = MAXBURST; 104 rate = MAXBURST;
110 105
111 m_burst = rate; 106 m_burst = rate;
@@ -114,11 +109,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
114 109
115 public float Burst 110 public float Burst
116 { 111 {
117 get { 112 get
118 float rate = RequestedBurst * BurstModifier(); 113 {
119 if (rate < MINBURST) 114 return RequestedBurst * BurstModifier(); ;
120 rate = MINBURST;
121 return (float)rate;
122 } 115 }
123 } 116 }
124 117
@@ -156,7 +149,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
156 if (rate < MINDRIPRATE) 149 if (rate < MINDRIPRATE)
157 rate = MINDRIPRATE; 150 rate = MINDRIPRATE;
158 151
159 return (float)rate; 152 return rate;
160 } 153 }
161 } 154 }
162 155
@@ -192,7 +185,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
192 Parent = parent; 185 Parent = parent;
193 RequestedDripRate = dripRate; 186 RequestedDripRate = dripRate;
194 RequestedBurst = MaxBurst; 187 RequestedBurst = MaxBurst;
195 m_lastDrip = Util.GetTimeStampMS() + 100000.0; // skip first drip 188 m_lastDrip = Util.GetTimeStamp() + 1000; // skip first drip
196 } 189 }
197 190
198#endregion Constructor 191#endregion Constructor
@@ -214,9 +207,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
214 /// </summary> 207 /// </summary>
215 protected float BurstModifier() 208 protected float BurstModifier()
216 { 209 {
217 // for now... burst rate is always m_quantumsPerBurst (constant)
218 // larger than drip rate so the ratio of burst requests is the
219 // same as the drip ratio
220 return DripRateModifier(); 210 return DripRateModifier();
221 } 211 }
222 212
@@ -272,10 +262,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
272 Drip(); 262 Drip();
273 263
274 // If we have enough tokens then remove them and return 264 // If we have enough tokens then remove them and return
275 if (m_tokenCount - amount >= 0) 265 if (m_tokenCount > 0)
276 { 266 {
277 // we don't have to remove from the parent, the drip rate is already
278 // reflective of the drip rate limits in the parent
279 m_tokenCount -= amount; 267 m_tokenCount -= amount;
280 return true; 268 return true;
281 } 269 }
@@ -285,12 +273,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
285 273
286 public bool CheckTokens(int amount) 274 public bool CheckTokens(int amount)
287 { 275 {
288 return (m_tokenCount - amount >= 0); 276 return (m_tokenCount > 0);
289 } 277 }
290 278
291 public int GetCatBytesCanSend(int timeMS) 279 public int GetCatBytesCanSend(int timeMS)
292 { 280 {
293// return (int)(m_tokenCount + timeMS * m_dripRate * 1e-3);
294 return (int)(timeMS * DripRate * 1e-3); 281 return (int)(timeMS * DripRate * 1e-3);
295 } 282 }
296 283
@@ -310,14 +297,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
310 return; 297 return;
311 } 298 }
312 299
313 double now = Util.GetTimeStampMS(); 300 double now = Util.GetTimeStamp();
314 double deltaMS = now - m_lastDrip; 301 double delta = now - m_lastDrip;
315 m_lastDrip = now; 302 m_lastDrip = now;
316 303
317 if (deltaMS <= 0) 304 if (delta <= 0)
318 return; 305 return;
319 306
320 m_tokenCount += (float)deltaMS * DripRate * m_timeScale; 307 m_tokenCount += (float)delta * DripRate;
321 308
322 float burst = Burst; 309 float burst = Burst;
323 if (m_tokenCount > burst) 310 if (m_tokenCount > burst)