diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs b/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs new file mode 100644 index 0000000..f8ec97a --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/UDP/ThrottleRates.cs | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Framework; | ||
30 | using Nini.Config; | ||
31 | |||
32 | namespace OpenSim.Region.ClientStack.LindenUDP | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Holds drip rates and maximum burst rates for throttling with hierarchical | ||
36 | /// token buckets. The maximum burst rates set here are hard limits and can | ||
37 | /// not be overridden by client requests | ||
38 | /// </summary> | ||
39 | public sealed class ThrottleRates | ||
40 | { | ||
41 | /// <summary>Drip rate for resent packets</summary> | ||
42 | public int Resend; | ||
43 | /// <summary>Drip rate for terrain packets</summary> | ||
44 | public int Land; | ||
45 | /// <summary>Drip rate for wind packets</summary> | ||
46 | public int Wind; | ||
47 | /// <summary>Drip rate for cloud packets</summary> | ||
48 | public int Cloud; | ||
49 | /// <summary>Drip rate for task packets</summary> | ||
50 | public int Task; | ||
51 | /// <summary>Drip rate for texture packets</summary> | ||
52 | public int Texture; | ||
53 | /// <summary>Drip rate for asset packets</summary> | ||
54 | public int Asset; | ||
55 | |||
56 | /// <summary>Drip rate for the parent token bucket</summary> | ||
57 | public int Total; | ||
58 | |||
59 | /// <summary>Flag used to enable adaptive throttles</summary> | ||
60 | public bool AdaptiveThrottlesEnabled; | ||
61 | |||
62 | /// <summary> | ||
63 | /// Set the minimum rate that the adaptive throttles can set. The viewer | ||
64 | /// can still throttle lower than this, but the adaptive throttles will | ||
65 | /// never decrease rates below this no matter how many packets are dropped | ||
66 | /// </summary> | ||
67 | public Int64 MinimumAdaptiveThrottleRate; | ||
68 | |||
69 | /// <summary>Amount of the texture throttle to steal for the task throttle</summary> | ||
70 | public double CannibalizeTextureRate; | ||
71 | |||
72 | public int ClientMaxRate; | ||
73 | public float BrustTime; | ||
74 | |||
75 | /// <summary> | ||
76 | /// Default constructor | ||
77 | /// </summary> | ||
78 | /// <param name="config">Config source to load defaults from</param> | ||
79 | public ThrottleRates(IConfigSource config) | ||
80 | { | ||
81 | try | ||
82 | { | ||
83 | IConfig throttleConfig = config.Configs["ClientStack.LindenUDP"]; | ||
84 | |||
85 | // Current default total is 66750 | ||
86 | Resend = throttleConfig.GetInt("resend_default", 6625); | ||
87 | Land = throttleConfig.GetInt("land_default", 9125); | ||
88 | Wind = throttleConfig.GetInt("wind_default", 1750); | ||
89 | Cloud = throttleConfig.GetInt("cloud_default", 1750); | ||
90 | Task = throttleConfig.GetInt("task_default", 18500); | ||
91 | Texture = throttleConfig.GetInt("texture_default", 18500); | ||
92 | Asset = throttleConfig.GetInt("asset_default", 10500); | ||
93 | |||
94 | Total = Resend + Land + Wind + Cloud + Task + Texture + Asset; | ||
95 | // 5120000 bps default max | ||
96 | ClientMaxRate = throttleConfig.GetInt("client_throttle_max_bps", 640000); | ||
97 | if (ClientMaxRate > 1000000) | ||
98 | ClientMaxRate = 1000000; // no more than 8Mbps | ||
99 | |||
100 | BrustTime = (float)throttleConfig.GetInt("client_throttle_burtsTimeMS", 10); | ||
101 | BrustTime *= 1e-3f; | ||
102 | |||
103 | // Adaptive is broken | ||
104 | // AdaptiveThrottlesEnabled = throttleConfig.GetBoolean("enable_adaptive_throttles", false); | ||
105 | AdaptiveThrottlesEnabled = false; | ||
106 | MinimumAdaptiveThrottleRate = throttleConfig.GetInt("adaptive_throttle_min_bps", 32000); | ||
107 | |||
108 | // http textures do use udp bandwidth setting | ||
109 | // CannibalizeTextureRate = (double)throttleConfig.GetFloat("CannibalizeTextureRate", 0.0f); | ||
110 | // CannibalizeTextureRate = Util.Clamp<double>(CannibalizeTextureRate,0.0, 0.9); | ||
111 | CannibalizeTextureRate = 0f; | ||
112 | |||
113 | } | ||
114 | catch (Exception) { } | ||
115 | } | ||
116 | |||
117 | public int GetRate(ThrottleOutPacketType type) | ||
118 | { | ||
119 | switch (type) | ||
120 | { | ||
121 | case ThrottleOutPacketType.Resend: | ||
122 | return Resend; | ||
123 | case ThrottleOutPacketType.Land: | ||
124 | return Land; | ||
125 | case ThrottleOutPacketType.Wind: | ||
126 | return Wind; | ||
127 | case ThrottleOutPacketType.Cloud: | ||
128 | return Cloud; | ||
129 | case ThrottleOutPacketType.Task: | ||
130 | return Task; | ||
131 | case ThrottleOutPacketType.Texture: | ||
132 | return Texture; | ||
133 | case ThrottleOutPacketType.Asset: | ||
134 | return Asset; | ||
135 | case ThrottleOutPacketType.Unknown: | ||
136 | default: | ||
137 | return 0; | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | } | ||