From 0c7e62ab5995a69cf59e29ab1ad314ead8975565 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Tue, 30 Apr 2013 20:36:00 +0200 Subject: [PATCH] Add throttling to HTTP inventory (bulk) fetching. Call AIPerService::wantsMoreHTTPRequestsFor in LLInventoryModelBackgroundFetch::bulkFetch to determine if curl is ready for the next batch or not, instead of using inaccurate heuristic code that is just guessing a bit. --- .../llinventorymodelbackgroundfetch.cpp | 31 ++++++++++--------- .../newview/llinventorymodelbackgroundfetch.h | 3 ++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/indra/newview/llinventorymodelbackgroundfetch.cpp b/indra/newview/llinventorymodelbackgroundfetch.cpp index 3fd1b52d2..a481a6720 100644 --- a/indra/newview/llinventorymodelbackgroundfetch.cpp +++ b/indra/newview/llinventorymodelbackgroundfetch.cpp @@ -37,6 +37,7 @@ #include "llviewermessage.h" #include "llviewerregion.h" #include "llviewerwindow.h" +#include "hippogridmanager.h" class AIHTTPTimeoutPolicy; extern AIHTTPTimeoutPolicy inventoryModelFetchDescendentsResponder_timeout; @@ -201,10 +202,20 @@ void LLInventoryModelBackgroundFetch::backgroundFetch() std::string url = region->getCapability("FetchInventory2"); if (gSavedSettings.getBOOL("UseHTTPInventory") && !url.empty()) { + if (!mPerServicePtr) + { + // One time initialization needed for bulkFetch(). + std::string servicename = AIPerService::extract_canonical_servicename(url); + if (!servicename.empty()) + { + llinfos << "Initialized service name for bulk inventory fetching with \"" << servicename << "\"." << llendl; + mPerServicePtr = AIPerService::instance(servicename); + } + } bulkFetch(); return; } - + #if 1 //-------------------------------------------------------------------------------- // DEPRECATED OLD CODE @@ -578,28 +589,20 @@ BOOL LLInventoryModelFetchDescendentsResponder::getIsRecursive(const LLUUID& cat } // Bundle up a bunch of requests to send all at once. -// static void LLInventoryModelBackgroundFetch::bulkFetch() { //Background fetch is called from gIdleCallbacks in a loop until background fetch is stopped. //If there are items in mFetchQueue, we want to check the time since the last bulkFetch was //sent. If it exceeds our retry time, go ahead and fire off another batch. LLViewerRegion* region = gAgent.getRegion(); - if (!region) return; + if (gDisconnected || !region) return; - S16 max_concurrent_fetches=8; - F32 new_min_time = 0.5f; //HACK! Clean this up when old code goes away entirely. - if (mMinTimeBetweenFetches < new_min_time) + static LLCachedControl const throttle_bandwidth("HTTPThrottleBandwidth", 2000); + bool const no_bandwidth_throttling = gHippoGridManager->getConnectedGrid()->isAvination(); + if (!AIPerService::wantsMoreHTTPRequestsFor(mPerServicePtr, throttle_bandwidth, no_bandwidth_throttling)) { - mMinTimeBetweenFetches=new_min_time; //HACK! See above. + return; // Wait. } - - if (gDisconnected || - (mFetchCount > max_concurrent_fetches) || - (mFetchTimer.getElapsedTimeF32() < mMinTimeBetweenFetches)) - { - return; // just bail if we are disconnected - } U32 item_count=0; U32 folder_count=0; diff --git a/indra/newview/llinventorymodelbackgroundfetch.h b/indra/newview/llinventorymodelbackgroundfetch.h index ac4c1a0c0..4056bdfbd 100644 --- a/indra/newview/llinventorymodelbackgroundfetch.h +++ b/indra/newview/llinventorymodelbackgroundfetch.h @@ -29,6 +29,7 @@ #include "llsingleton.h" #include "lluuid.h" +#include "aicurlperservice.h" //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Class LLInventoryModelBackgroundFetch @@ -81,6 +82,8 @@ private: BOOL mTimelyFetchPending; S32 mNumFetchRetries; + AIPerServicePtr mPerServicePtr; // Pointer to the AIPerService corresponding to the FetchInventory2 capability. + LLFrameTimer mFetchTimer; F32 mMinTimeBetweenFetches; F32 mMaxTimeBetweenFetches;