ThrottleRates.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 the parent token bucket</summary>
  54. public int Total;
  55. /// <summary>Flag used to enable adaptive throttles</summary>
  56. public bool AdaptiveThrottlesEnabled;
  57. /// <summary>
  58. /// Set the minimum rate that the adaptive throttles can set. The viewer
  59. /// can still throttle lower than this, but the adaptive throttles will
  60. /// never decrease rates below this no matter how many packets are dropped
  61. /// </summary>
  62. public Int64 MinimumAdaptiveThrottleRate;
  63. /// <summary>Amount of the texture throttle to steal for the task throttle</summary>
  64. public double CannibalizeTextureRate;
  65. public int ClientMaxRate;
  66. public float BrustTime;
  67. /// <summary>
  68. /// Default constructor
  69. /// </summary>
  70. /// <param name="config">Config source to load defaults from</param>
  71. public ThrottleRates(IConfigSource config)
  72. {
  73. try
  74. {
  75. IConfig throttleConfig = config.Configs["ClientStack.LindenUDP"];
  76. // Current default total is 66750
  77. Resend = throttleConfig.GetInt("resend_default", 6625);
  78. Land = throttleConfig.GetInt("land_default", 9125);
  79. Wind = throttleConfig.GetInt("wind_default", 1750);
  80. Cloud = throttleConfig.GetInt("cloud_default", 1750);
  81. Task = throttleConfig.GetInt("task_default", 18500);
  82. Texture = throttleConfig.GetInt("texture_default", 18500);
  83. Asset = throttleConfig.GetInt("asset_default", 10500);
  84. Total = Resend + Land + Wind + Cloud + Task + Texture + Asset;
  85. // 5120000 bps default max
  86. ClientMaxRate = throttleConfig.GetInt("client_throttle_max_bps", 640000);
  87. if (ClientMaxRate > 1000000)
  88. ClientMaxRate = 1000000; // no more than 8Mbps
  89. BrustTime = (float)throttleConfig.GetInt("client_throttle_burtsTimeMS", 10);
  90. BrustTime *= 1e-3f;
  91. // Adaptive is broken
  92. // AdaptiveThrottlesEnabled = throttleConfig.GetBoolean("enable_adaptive_throttles", false);
  93. AdaptiveThrottlesEnabled = false;
  94. MinimumAdaptiveThrottleRate = throttleConfig.GetInt("adaptive_throttle_min_bps", 32000);
  95. // http textures do use udp bandwidth setting
  96. // CannibalizeTextureRate = (double)throttleConfig.GetFloat("CannibalizeTextureRate", 0.0f);
  97. // CannibalizeTextureRate = Util.Clamp<double>(CannibalizeTextureRate,0.0, 0.9);
  98. CannibalizeTextureRate = 0f;
  99. }
  100. catch (Exception) { }
  101. }
  102. public int GetRate(ThrottleOutPacketType type)
  103. {
  104. switch (type)
  105. {
  106. case ThrottleOutPacketType.Resend:
  107. return Resend;
  108. case ThrottleOutPacketType.Land:
  109. return Land;
  110. case ThrottleOutPacketType.Wind:
  111. return Wind;
  112. case ThrottleOutPacketType.Cloud:
  113. return Cloud;
  114. case ThrottleOutPacketType.Task:
  115. return Task;
  116. case ThrottleOutPacketType.Texture:
  117. return Texture;
  118. case ThrottleOutPacketType.Asset:
  119. return Asset;
  120. case ThrottleOutPacketType.Unknown:
  121. default:
  122. return 0;
  123. }
  124. }
  125. }
  126. }