Preparation for AIPerService::checkBandwidthUsage.

Don't pass arguments to wantsMoreHTTPRequestsFor, but use globals in
llmessage: AIPerService::sHTTPThrottleBandwidth125 and
AIPerService::sNoHTTPBandwidthThrottling instead.

This is needed later on.
This commit is contained in:
Aleric Inglewood
2013-05-05 19:19:34 +02:00
parent 32a5494c79
commit fd3e8e4a23
7 changed files with 33 additions and 22 deletions

View File

@@ -89,7 +89,7 @@ class AIPerService {
static threadsafe_instance_map_type sInstanceMap; // Map of AIPerService instances with the hostname as key.
friend class AIThreadSafeSimpleDC<AIPerService>; //threadsafe_PerServiceRequestQueue
friend class AIThreadSafeSimpleDC<AIPerService>; // threadsafe_PerServiceRequestQueue
AIPerService(void);
public:
@@ -138,6 +138,8 @@ class AIPerService {
static U64 sLastTime_ThrottleFractionAverage_add; // Last time that sThrottleFraction was added to sThrottleFractionAverage.
static size_t sThrottleFraction; // A value between 0 and 1024: each service is throttled when it uses more than max_bandwidth * (sThrottleFraction/1024) bandwidth.
static AIAverage sThrottleFractionAverage; // Average of sThrottleFraction over 25 * 40ms = 1 second.
static size_t sHTTPThrottleBandwidth125; // HTTPThrottleBandwidth times 125 (in bytes/s).
static bool sNoHTTPBandwidthThrottling; // Global override to disable bandwidth throttling.
public:
void added_to_command_queue(void) { ++mQueuedCommands; }
@@ -159,13 +161,17 @@ class AIPerService {
AIAverage& bandwidth(void) { return mHTTPBandwidth; }
AIAverage const& bandwidth(void) const { return mHTTPBandwidth; }
static void setNoHTTPBandwidthThrottling(bool nb) { sNoHTTPBandwidthThrottling = nb; }
static void setHTTPThrottleBandwidth(F32 max_kbps) { sHTTPThrottleBandwidth125 = 125.f * max_kbps; }
static size_t getHTTPThrottleBandwidth125(void) { return sHTTPThrottleBandwidth125; }
// Called when CurlConcurrentConnectionsPerService changes.
static void adjust_concurrent_connections(int increment);
// Returns true if curl can handle another request for this host.
// Should return false if the maximum allowed HTTP bandwidth is reached, or when
// the latency between request and actual delivery becomes too large.
static bool wantsMoreHTTPRequestsFor(AIPerServicePtr const& per_service, F32 max_kbps, bool no_bandwidth_throttling);
static bool wantsMoreHTTPRequestsFor(AIPerServicePtr const& per_service);
// Accessor for when curl_max_total_concurrent_connections changes.
static LLAtomicS32& maxPipelinedRequests(void) { return sMaxPipelinedRequests; }

View File

@@ -2510,6 +2510,7 @@ void startCurlThread(LLControlGroup* control_group)
CurlConcurrentConnectionsPerService = sConfigGroup->getU32("CurlConcurrentConnectionsPerService");
gNoVerifySSLCert = sConfigGroup->getBOOL("NoVerifySSLCert");
AIPerService::maxPipelinedRequests() = curl_max_total_concurrent_connections;
AIPerService::setHTTPThrottleBandwidth(sConfigGroup->getF32("HTTPThrottleBandwidth"));
AICurlThread::sInstance = new AICurlThread;
AICurlThread::sInstance->start();
@@ -2579,6 +2580,8 @@ LLAtomicS32 AIPerService::sMaxPipelinedRequests(32);
U64 AIPerService::sLastTime_ThrottleFractionAverage_add = 0;
size_t AIPerService::sThrottleFraction = 1024;
AIAverage AIPerService::sThrottleFractionAverage(25);
size_t AIPerService::sHTTPThrottleBandwidth125 = 250000;
bool AIPerService::sNoHTTPBandwidthThrottling;
// Return true if we want at least one more HTTP request for this host.
//
@@ -2605,7 +2608,7 @@ AIAverage AIPerService::sThrottleFractionAverage(25);
// running requests (in MultiHandle::mAddedEasyRequests)).
//
//static
bool AIPerService::wantsMoreHTTPRequestsFor(AIPerServicePtr const& per_service, F32 max_kbps, bool no_bandwidth_throttling)
bool AIPerService::wantsMoreHTTPRequestsFor(AIPerServicePtr const& per_service)
{
using namespace AICurlPrivate;
using namespace AICurlPrivate::curlthread;
@@ -2674,12 +2677,12 @@ bool AIPerService::wantsMoreHTTPRequestsFor(AIPerServicePtr const& per_service,
return false;
}
if (!no_bandwidth_throttling)
if (!sNoHTTPBandwidthThrottling)
{
// Throttle on bandwidth usage.
// Truncate the sums to the last second, and get their value.
size_t const max_bandwidth = 125.f * max_kbps; // Convert kbps to bytes per second.
size_t const max_bandwidth = AIPerService::getHTTPThrottleBandwidth125();
size_t const total_bandwidth = BufferedCurlEasyRequest::sHTTPBandwidth.truncateData(sTime_40ms); // Bytes received in the past second.
size_t const service_bandwidth = http_bandwidth_ptr->truncateData(sTime_40ms); // Idem for just this service.
if (sTime_40ms > sLastTime_ThrottleFractionAverage_add)
@@ -2709,7 +2712,7 @@ bool AIPerService::wantsMoreHTTPRequestsFor(AIPerServicePtr const& per_service,
// max_bandwidth / total_bandwidth.
//
// For example, let max_bandwidth be 1. Let there be two throttled
// services, each using 0.5 (fraction_avg = 1024/2). Lets the new
// services, each using 0.5 (fraction_avg = 1024/2). Let the new
// service use what it can: also 0.5 - then without reduction the
// total_bandwidth would become 1.5, and sThrottleFraction would
// become (1024/2) * 1/1.5 = 1024/3: from 2 to 3 services.

View File

@@ -600,9 +600,7 @@ void LLInventoryModelBackgroundFetch::bulkFetch()
LLViewerRegion* region = gAgent.getRegion();
if (gDisconnected || !region) return;
static LLCachedControl<F32> const throttle_bandwidth("HTTPThrottleBandwidth", 2000);
bool const no_bandwidth_throttling = gHippoGridManager->getConnectedGrid()->isAvination();
if (!AIPerService::wantsMoreHTTPRequestsFor(mPerServicePtr, throttle_bandwidth, no_bandwidth_throttling))
if (!AIPerService::wantsMoreHTTPRequestsFor(mPerServicePtr))
{
return; // Wait.
}

View File

@@ -1008,6 +1008,8 @@ bool idle_startup()
LLTrans::setDefaultArg("[GRID_OWNER]", gHippoGridManager->getConnectedGrid()->getGridOwner());
LLScriptEdCore::parseFunctions("lsl_functions_os.xml"); //Singu Note: This appends to the base functions parsed from lsl_functions_sl.xml
}
// Avination doesn't want the viewer to do bandwidth throttling (it is done serverside, taking UDP into account too).
AIPerService::setNoHTTPBandwidthThrottling(gHippoGridManager->getConnectedGrid()->isAvination());
// create necessary directories
// *FIX: these mkdir's should error check

View File

@@ -1272,9 +1272,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
}
// Let AICurl decide if we can process more HTTP requests at the moment or not.
static const LLCachedControl<F32> throttle_bandwidth("HTTPThrottleBandwidth", 2000);
bool const no_bandwidth_throttling = gHippoGridManager->getConnectedGrid()->isAvination();
if (!AIPerService::wantsMoreHTTPRequestsFor(mPerServicePtr, throttle_bandwidth, no_bandwidth_throttling))
if (!AIPerService::wantsMoreHTTPRequestsFor(mPerServicePtr))
{
return false ; //wait.
}

View File

@@ -37,6 +37,7 @@
#include "llimageworker.h"
#include "llrender.h"
#include "aicurlperservice.h"
#include "llappviewer.h"
#include "llselectmgr.h"
#include "llviewertexlayer.h"
@@ -621,18 +622,15 @@ void LLGLTexMemBar::draw()
text_color, LLFontGL::LEFT, LLFontGL::TOP);
left += LLFontGL::getFontMonospace()->getWidth(text);
// This bandwidth is averaged over 1 seconds (in kbps).
F32 bandwidth = AICurlInterface::getHTTPBandwidth() / 125.f; // Convert from bytes/s to kbps.
// This is the maximum bandwidth allowed for curl transactions (of any type and averaged per second),
// that is actually used to limit the number of HTTP texture requests (and only those).
// Comparing that with 'bandwidth' is a bit like comparing apples and oranges, but again... who really cares.
static const LLCachedControl<F32> max_bandwidth("HTTPThrottleBandwidth", 2000);
color = bandwidth > max_bandwidth ? LLColor4::red : bandwidth > max_bandwidth*.75f ? LLColor4::yellow : text_color;
// This bandwidth is averaged over 1 seconds (in bytes/s).
size_t const bandwidth = AICurlInterface::getHTTPBandwidth();
size_t const max_bandwidth = AIPerService::getHTTPThrottleBandwidth125();
color = (bandwidth > max_bandwidth) ? LLColor4::red : ((bandwidth > max_bandwidth * .75f) ? LLColor4::yellow : text_color);
color[VALPHA] = text_color[VALPHA];
text = llformat("BW:%.0f/%.0f", bandwidth, max_bandwidth.get());
text = llformat("BW:%lu/%lu", bandwidth / 125, max_bandwidth / 125);
LLFontGL::getFontMonospace()->renderUTF8(text, 0, left, v_offset + line_height*2,
color, LLFontGL::LEFT, LLFontGL::TOP);
S32 dx1 = 0;
if (LLAppViewer::getTextureFetch()->mDebugPause)
{

View File

@@ -84,7 +84,6 @@
#include "aicurl.h"
#include "aihttptimeoutpolicy.h"
#ifdef TOGGLE_HACKED_GODLIKE_VIEWER
BOOL gHackGodmode = FALSE;
#endif
@@ -330,6 +329,12 @@ static bool handleBandwidthChanged(const LLSD& newvalue)
return true;
}
static bool handleHTTPBandwidthChanged(const LLSD& newvalue)
{
AIPerService::setHTTPThrottleBandwidth((F32) newvalue.asReal());
return true;
}
static bool handleChatFontSizeChanged(const LLSD& newvalue)
{
if(gConsole)
@@ -666,6 +671,7 @@ void settings_setup_listeners()
gSavedSettings.getControl("RenderTreeLODFactor")->getSignal()->connect(boost::bind(&handleTreeLODChanged, _2));
gSavedSettings.getControl("RenderFlexTimeFactor")->getSignal()->connect(boost::bind(&handleFlexLODChanged, _2));
gSavedSettings.getControl("ThrottleBandwidthKBPS")->getSignal()->connect(boost::bind(&handleBandwidthChanged, _2));
gSavedSettings.getControl("HTTPThrottleBandwidth")->getSignal()->connect(boost::bind(&handleHTTPBandwidthChanged, _2));
gSavedSettings.getControl("RenderGamma")->getSignal()->connect(boost::bind(&handleGammaChanged, _2));
gSavedSettings.getControl("RenderFogRatio")->getSignal()->connect(boost::bind(&handleFogRatioChanged, _2));
gSavedSettings.getControl("RenderMaxPartCount")->getSignal()->connect(boost::bind(&handleMaxPartCountChanged, _2));