llthrottle.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * @file llthrottle.h
  3. * @brief LLThrottle class used for network bandwidth control
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLTHROTTLE_H
  33. #define LL_LLTHROTTLE_H
  34. #include "llpreprocessor.h"
  35. #include "lltimer.h"
  36. constexpr S32 MAX_THROTTLE_SIZE = 32;
  37. class LLDataPacker;
  38. // Single instance of a generic throttle
  39. class LLThrottle
  40. {
  41. public:
  42. LLThrottle(F32 throttle = 1.f);
  43. ~LLThrottle() {}
  44. void setRate(F32 rate);
  45. // About to add an amount, true if would overflow throttle
  46. bool checkOverflow(F32 amount);
  47. // Just sent amount, true if that overflowed the throttle
  48. bool throttleOverflow(F32 amount);
  49. F32 getAvailable(); // Returns the available bits
  50. LL_INLINE F32 getRate() const { return mRate; }
  51. private:
  52. F32 mLookaheadSecs; // Seconds to look ahead, maximum
  53. F32 mRate; // bps available, dynamically adjusted
  54. F32 mAvailable; // Bits available to send right now on each channel
  55. F64 mLastSendTime; // Time since last send on this channel
  56. };
  57. typedef enum e_throttle_categories
  58. {
  59. TC_RESEND,
  60. TC_LAND,
  61. TC_WIND,
  62. TC_CLOUD,
  63. TC_TASK,
  64. TC_TEXTURE,
  65. TC_ASSET,
  66. TC_EOF
  67. } EThrottleCats;
  68. class LLThrottleGroup
  69. {
  70. public:
  71. LLThrottleGroup();
  72. ~LLThrottleGroup() {}
  73. void resetDynamicAdjust();
  74. // About to send bits, true if would overflow channel
  75. bool checkOverflow(S32 throttle_cat, F32 bits);
  76. // Just sent bits, true if that overflowed the channel
  77. bool throttleOverflow(S32 throttle_cat, F32 bits);
  78. // Shift bandwidth from idle channels to busy channels, true if adjustment
  79. // occurred
  80. bool dynamicAdjust();
  81. // true if any value was different, resets adjustment system if was
  82. // different
  83. bool setNominalBPS(F32* throttle_vec);
  84. // Returns bits available in the channel
  85. S32 getAvailable(S32 throttle_cat);
  86. void packThrottle(LLDataPacker& dp) const;
  87. void unpackThrottle(LLDataPacker& dp);
  88. public:
  89. // bps available, sent by viewer, sum for all simulators
  90. F32 mThrottleTotal[TC_EOF];
  91. protected:
  92. // bps available, adjusted to be just this simulator
  93. F32 mNominalBPS[TC_EOF];
  94. // bps available, dynamically adjusted
  95. F32 mCurrentBPS[TC_EOF];
  96. // Bits available to send right now on each channel
  97. F32 mBitsAvailable[TC_EOF];
  98. // Sent in this dynamic allocation period
  99. F32 mBitsSentThisPeriod[TC_EOF];
  100. // Sent before this dynamic allocation period, adjusted to one period
  101. // length
  102. F32 mBitsSentHistory[TC_EOF];
  103. // Time since last send on this channel
  104. F64 mLastSendTime[TC_EOF];
  105. // Only dynamic adjust every 2 seconds or so.
  106. F64 mDynamicAdjustTime;
  107. };
  108. #endif