#3644 Adjust throttle based of how busy buffer is

master
Andrey Kleshchev 2025-03-13 23:55:38 +02:00 committed by Andrey Kleshchev
parent d3d0728bac
commit c99e3167ed
6 changed files with 23 additions and 6 deletions

View File

@ -344,6 +344,12 @@ bool LLPacketRing::expandRing()
return true;
}
F32 LLPacketRing::getBufferLoadRate() const
{
// goes up to MAX_BUFFER_RING_SIZE
return (F32)mNumBufferedPackets / (F32)DEFAULT_BUFFER_RING_SIZE;
}
void LLPacketRing::dumpPacketRingStats()
{
mNumDroppedPacketsTotal += mNumDroppedPackets;

View File

@ -64,6 +64,7 @@ public:
S32 getNumBufferedBytes() const { return mNumBufferedBytes; }
S32 getNumDroppedPackets() const { return mNumDroppedPacketsTotal + mNumDroppedPackets; }
F32 getBufferLoadRate() const; // from 0 to 4 (0 - empty, 1 - default size is full)
void dumpPacketRingStats();
protected:
// returns 'true' if we should intentionally drop a packet

View File

@ -538,7 +538,6 @@ public:
//void buildMessage();
S32 zeroCode(U8 **data, S32 *data_size);
S32 zeroCodeExpand(U8 **data, S32 *data_size);
S32 zeroCodeAdjustCurrentSendTotal();
@ -755,6 +754,7 @@ public:
S32 getReceiveBytes() const;
S32 getUnackedListSize() const { return mUnackedListSize; }
F32 getBufferLoadRate() const { return mPacketRing.getBufferLoadRate(); }
//const char* getCurrentSMessageName() const { return mCurrentSMessageName; }
//const char* getCurrentSBlockName() const { return mCurrentSBlockName; }
@ -842,12 +842,10 @@ private:
LLUUID mSessionID;
void addTemplate(LLMessageTemplate *templatep);
bool decodeTemplate( const U8* buffer, S32 buffer_size, LLMessageTemplate** msg_template );
void logMsgFromInvalidCircuit( const LLHost& sender, bool recv_reliable );
void logTrustedMsgFromUntrustedCircuit( const LLHost& sender );
void logValidMsg(LLCircuitData *cdp, const LLHost& sender, bool recv_reliable, bool recv_resent, bool recv_acks );
void logRanOffEndOfPacket( const LLHost& sender );
class LLMessageCountInfo
{

View File

@ -5443,6 +5443,7 @@ void LLAppViewer::idleNetwork()
// Retransmit unacknowledged packets.
gXferManager->retransmitUnackedPackets();
gAssetStorage->checkForTimeouts();
gViewerThrottle.setBufferLoadRate(gMessageSystem->getBufferLoadRate());
gViewerThrottle.updateDynamicThrottle();
// Check that the circuit between the viewer and the agent's current

View File

@ -48,6 +48,8 @@ const F32 MIN_FRACTIONAL = 0.2f;
const F32 MIN_BANDWIDTH = 50.f;
const F32 MAX_BANDWIDTH = 6000.f;
const F32 STEP_FRACTIONAL = 0.1f;
const F32 HIGH_BUFFER_LOAD_TRESHOLD = 1.f;
const F32 LOW_BUFFER_LOAD_TRESHOLD = 0.8f;
const LLUnit<F32, LLUnits::Percent> TIGHTEN_THROTTLE_THRESHOLD(3.0f); // packet loss % per s
const LLUnit<F32, LLUnits::Percent> EASE_THROTTLE_THRESHOLD(0.5f); // packet loss % per s
const F32 DYNAMIC_UPDATE_DURATION = 5.0f; // seconds
@ -146,7 +148,7 @@ LLViewerThrottleGroup LLViewerThrottleGroup::operator-(const LLViewerThrottleGro
void LLViewerThrottleGroup::sendToSim() const
{
LL_INFOS() << "Sending throttle settings, total BW " << mThrottleTotal << LL_ENDL;
LL_DEBUGS("Throttle") << "Sending throttle settings, total BW " << mThrottleTotal << LL_ENDL;
LLMessageSystem* msg = gMessageSystem;
msg->newMessageFast(_PREHASH_AgentThrottle);
@ -305,7 +307,10 @@ void LLViewerThrottle::updateDynamicThrottle()
mUpdateTimer.reset();
LLUnit<F32, LLUnits::Percent> mean_packets_lost = LLViewerStats::instance().getRecording().getMean(LLStatViewer::PACKETS_LOST_PERCENT);
if (mean_packets_lost > TIGHTEN_THROTTLE_THRESHOLD)
if (
mean_packets_lost > TIGHTEN_THROTTLE_THRESHOLD // already losing packets
|| mBufferLoadRate >= HIGH_BUFFER_LOAD_TRESHOLD // let viewer sort through the backlog before it starts dropping packets
)
{
if (mThrottleFrac <= MIN_FRACTIONAL || mCurrentBandwidth / 1024.0f <= MIN_BANDWIDTH)
{
@ -318,7 +323,8 @@ void LLViewerThrottle::updateDynamicThrottle()
mCurrent.sendToSim();
LL_INFOS() << "Tightening network throttle to " << mCurrentBandwidth << LL_ENDL;
}
else if (mean_packets_lost <= EASE_THROTTLE_THRESHOLD)
else if (mean_packets_lost <= EASE_THROTTLE_THRESHOLD
&& mBufferLoadRate < LOW_BUFFER_LOAD_TRESHOLD)
{
if (mThrottleFrac >= MAX_FRACTIONAL || mCurrentBandwidth / 1024.0f >= MAX_BANDWIDTH)
{
@ -331,4 +337,6 @@ void LLViewerThrottle::updateDynamicThrottle()
mCurrent.sendToSim();
LL_INFOS() << "Easing network throttle to " << mCurrentBandwidth << LL_ENDL;
}
mBufferLoadRate = 0;
}

View File

@ -70,12 +70,15 @@ public:
void updateDynamicThrottle();
void resetDynamicThrottle();
void setBufferLoadRate(F32 rate) { mBufferLoadRate = llmax(mBufferLoadRate, rate); }
LLViewerThrottleGroup getThrottleGroup(const F32 bandwidth_kbps);
static const std::string sNames[TC_EOF];
protected:
F32 mMaxBandwidth;
F32 mCurrentBandwidth;
F32 mBufferLoadRate = 0;
LLViewerThrottleGroup mCurrent;