ThrottleRates.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. using System;
  28. using OpenSim.Framework;
  29. using Nini.Config;
  30. namespace OpenSim.Region.ClientStack.LindenUDP
  31. {
  32. /// <summary>
  33. /// Holds drip rates and maximum burst rates for throttling with hierarchical
  34. /// token buckets. The maximum burst rates set here are hard limits and can
  35. /// not be overridden by client requests
  36. /// </summary>
  37. public sealed class ThrottleRates
  38. {
  39. /// <summary>Drip rate for resent packets</summary>
  40. public int Resend;
  41. /// <summary>Drip rate for terrain packets</summary>
  42. public int Land;
  43. /// <summary>Drip rate for wind packets</summary>
  44. public int Wind;
  45. /// <summary>Drip rate for cloud packets</summary>
  46. public int Cloud;
  47. /// <summary>Drip rate for task packets</summary>
  48. public int Task;
  49. /// <summary>Drip rate for texture packets</summary>
  50. public int Texture;
  51. /// <summary>Drip rate for asset packets</summary>
  52. public int Asset;
  53. /// <summary>Drip rate for state packets</summary>
  54. public int State;
  55. /// <summary>Drip rate for the parent token bucket</summary>
  56. public int Total;
  57. /// <summary>Maximum burst rate for resent packets</summary>
  58. public int ResendLimit;
  59. /// <summary>Maximum burst rate for land packets</summary>
  60. public int LandLimit;
  61. /// <summary>Maximum burst rate for wind packets</summary>
  62. public int WindLimit;
  63. /// <summary>Maximum burst rate for cloud packets</summary>
  64. public int CloudLimit;
  65. /// <summary>Maximum burst rate for task (state and transaction) packets</summary>
  66. public int TaskLimit;
  67. /// <summary>Maximum burst rate for texture packets</summary>
  68. public int TextureLimit;
  69. /// <summary>Maximum burst rate for asset packets</summary>
  70. public int AssetLimit;
  71. /// <summary>Maximum burst rate for state packets</summary>
  72. public int StateLimit;
  73. /// <summary>Burst rate for the parent token bucket</summary>
  74. public int TotalLimit;
  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. Resend = throttleConfig.GetInt("resend_default", 12500);
  85. Land = throttleConfig.GetInt("land_default", 1000);
  86. Wind = throttleConfig.GetInt("wind_default", 1000);
  87. Cloud = throttleConfig.GetInt("cloud_default", 1000);
  88. Task = throttleConfig.GetInt("task_default", 1000);
  89. Texture = throttleConfig.GetInt("texture_default", 1000);
  90. Asset = throttleConfig.GetInt("asset_default", 1000);
  91. State = throttleConfig.GetInt("state_default", 1000);
  92. ResendLimit = throttleConfig.GetInt("resend_limit", 18750);
  93. LandLimit = throttleConfig.GetInt("land_limit", 29750);
  94. WindLimit = throttleConfig.GetInt("wind_limit", 18750);
  95. CloudLimit = throttleConfig.GetInt("cloud_limit", 18750);
  96. TaskLimit = throttleConfig.GetInt("task_limit", 18750);
  97. TextureLimit = throttleConfig.GetInt("texture_limit", 55750);
  98. AssetLimit = throttleConfig.GetInt("asset_limit", 27500);
  99. StateLimit = throttleConfig.GetInt("state_limit", 37000);
  100. Total = throttleConfig.GetInt("client_throttle_max_bps", 0);
  101. TotalLimit = Total;
  102. }
  103. catch (Exception) { }
  104. }
  105. public int GetRate(ThrottleOutPacketType type)
  106. {
  107. switch (type)
  108. {
  109. case ThrottleOutPacketType.Resend:
  110. return Resend;
  111. case ThrottleOutPacketType.Land:
  112. return Land;
  113. case ThrottleOutPacketType.Wind:
  114. return Wind;
  115. case ThrottleOutPacketType.Cloud:
  116. return Cloud;
  117. case ThrottleOutPacketType.Task:
  118. return Task;
  119. case ThrottleOutPacketType.Texture:
  120. return Texture;
  121. case ThrottleOutPacketType.Asset:
  122. return Asset;
  123. case ThrottleOutPacketType.State:
  124. return State;
  125. case ThrottleOutPacketType.Unknown:
  126. default:
  127. return 0;
  128. }
  129. }
  130. public int GetLimit(ThrottleOutPacketType type)
  131. {
  132. switch (type)
  133. {
  134. case ThrottleOutPacketType.Resend:
  135. return ResendLimit;
  136. case ThrottleOutPacketType.Land:
  137. return LandLimit;
  138. case ThrottleOutPacketType.Wind:
  139. return WindLimit;
  140. case ThrottleOutPacketType.Cloud:
  141. return CloudLimit;
  142. case ThrottleOutPacketType.Task:
  143. return TaskLimit;
  144. case ThrottleOutPacketType.Texture:
  145. return TextureLimit;
  146. case ThrottleOutPacketType.Asset:
  147. return AssetLimit;
  148. case ThrottleOutPacketType.State:
  149. return StateLimit;
  150. case ThrottleOutPacketType.Unknown:
  151. default:
  152. return 0;
  153. }
  154. }
  155. }
  156. }