PageRenderTime 43ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llthrottle.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 101 lines | 57 code | 18 blank | 26 comment | 0 complexity | f93ce5d81bc70a2021ee5300da1ce818 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llthrottle.h
  3. * @brief LLThrottle class used for network bandwidth control
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLTHROTTLE_H
  27. #define LL_LLTHROTTLE_H
  28. #include "lltimer.h"
  29. const S32 MAX_THROTTLE_SIZE = 32;
  30. class LLDataPacker;
  31. // Single instance of a generic throttle
  32. class LLThrottle
  33. {
  34. public:
  35. LLThrottle(const F32 throttle = 1.f);
  36. ~LLThrottle() { }
  37. void setRate(const F32 rate);
  38. BOOL checkOverflow(const F32 amount); // I'm about to add an amount, TRUE if would overflow throttle
  39. BOOL throttleOverflow(const F32 amount); // I just sent amount, TRUE if that overflowed the throttle
  40. F32 getAvailable(); // Return the available bits
  41. F32 getRate() const { return mRate; }
  42. private:
  43. F32 mLookaheadSecs; // Seconds to look ahead, maximum
  44. F32 mRate; // BPS available, dynamically adjusted
  45. F32 mAvailable; // Bits available to send right now on each channel
  46. F64 mLastSendTime; // Time since last send on this channel
  47. };
  48. typedef enum e_throttle_categories
  49. {
  50. TC_RESEND,
  51. TC_LAND,
  52. TC_WIND,
  53. TC_CLOUD,
  54. TC_TASK,
  55. TC_TEXTURE,
  56. TC_ASSET,
  57. TC_EOF
  58. } EThrottleCats;
  59. class LLThrottleGroup
  60. {
  61. public:
  62. LLThrottleGroup();
  63. ~LLThrottleGroup() { }
  64. void resetDynamicAdjust();
  65. BOOL checkOverflow(S32 throttle_cat, F32 bits); // I'm about to send bits, TRUE if would overflow channel
  66. BOOL throttleOverflow(S32 throttle_cat, F32 bits); // I just sent bits, TRUE if that overflowed the channel
  67. BOOL dynamicAdjust(); // Shift bandwidth from idle channels to busy channels, TRUE if adjustment occurred
  68. BOOL setNominalBPS(F32* throttle_vec); // TRUE if any value was different, resets adjustment system if was different
  69. S32 getAvailable(S32 throttle_cat); // Return bits available in the channel
  70. void packThrottle(LLDataPacker &dp) const;
  71. void unpackThrottle(LLDataPacker &dp);
  72. public:
  73. F32 mThrottleTotal[TC_EOF]; // BPS available, sent by viewer, sum for all simulators
  74. protected:
  75. F32 mNominalBPS[TC_EOF]; // BPS available, adjusted to be just this simulator
  76. F32 mCurrentBPS[TC_EOF]; // BPS available, dynamically adjusted
  77. F32 mBitsAvailable[TC_EOF]; // Bits available to send right now on each channel
  78. F32 mBitsSentThisPeriod[TC_EOF]; // Sent in this dynamic allocation period
  79. F32 mBitsSentHistory[TC_EOF]; // Sent before this dynamic allocation period, adjusted to one period length
  80. F64 mLastSendTime[TC_EOF]; // Time since last send on this channel
  81. F64 mDynamicAdjustTime; // Only dynamic adjust every 2 seconds or so.
  82. };
  83. #endif