diff options
author | Monty Brandenberg <monty@lindenlab.com> | 2012-07-19 13:41:18 -0400 |
---|---|---|
committer | Monty Brandenberg <monty@lindenlab.com> | 2012-07-19 13:41:18 -0400 |
commit | 3f032e33f2b2f929b229cf4d358b9c9d297856b8 (patch) | |
tree | d09d11e70b12c42721f51baedf8af3e795d3f8da /indra/newview | |
parent | c9f5bc7cae793b6965ceb9490243b4c52017c254 (diff) |
SH-3280 Better init/shutdown functionality for llcorehttp by llappviewer
Isolate llcorehttp initialization into a utility class (LLAppCoreHttp)
that provides glue between app and library (sets up policies, handles
notifications). Introduce 'TextureFetchConcurrency' debug setting to
provide some field control when absolutely necessary.
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/CMakeLists.txt | 2 | ||||
-rw-r--r-- | indra/newview/app_settings/settings.xml | 11 | ||||
-rw-r--r-- | indra/newview/llappcorehttp.cpp | 186 | ||||
-rw-r--r-- | indra/newview/llappcorehttp.h | 86 | ||||
-rw-r--r-- | indra/newview/llappviewer.cpp | 189 | ||||
-rw-r--r-- | indra/newview/llappviewer.h | 7 | ||||
-rwxr-xr-x | indra/newview/lltexturefetch.cpp | 9 | ||||
-rw-r--r-- | indra/newview/lltexturefetch.h | 12 |
8 files changed, 310 insertions, 192 deletions
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index ab81cadc96..94286f0ff4 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -91,6 +91,7 @@ set(viewer_SOURCE_FILES llagentwearables.cpp llagentwearablesfetch.cpp llanimstatelabels.cpp + llappcorehttp.cpp llappearancemgr.cpp llappviewer.cpp llappviewerlistener.cpp @@ -648,6 +649,7 @@ set(viewer_HEADER_FILES llagentwearables.h llagentwearablesfetch.h llanimstatelabels.h + llappcorehttp.h llappearance.h llappearancemgr.h llappviewer.h diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index c9b4de0140..fc32e65410 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -10743,6 +10743,17 @@ <key>Value</key> <integer>0</integer> </map> + <key>TextureFetchConcurrency</key> + <map> + <key>Comment</key> + <string>Maximum number of HTTP connections used for texture fetches</string> + <key>Persist</key> + <integer>1</integer> + <key>Type</key> + <string>U32</string> + <key>Value</key> + <integer>0</integer> + </map> <key>TextureFetchDebuggerEnabled</key> <map> <key>Comment</key> diff --git a/indra/newview/llappcorehttp.cpp b/indra/newview/llappcorehttp.cpp new file mode 100644 index 0000000000..e89c8d5ac2 --- /dev/null +++ b/indra/newview/llappcorehttp.cpp @@ -0,0 +1,186 @@ +/** + * @file llappcorehttp.cpp + * @brief + * + * $LicenseInfo:firstyear=2012&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llappcorehttp.h" + +#include "llviewercontrol.h" + + +const F64 LLAppCoreHttp::MAX_THREAD_WAIT_TIME(10.0); + +LLAppCoreHttp::LLAppCoreHttp() + : mRequest(NULL), + mStopHandle(LLCORE_HTTP_HANDLE_INVALID), + mStopRequested(0.0), + mStopped(false), + mPolicyDefault(-1) +{} + + +LLAppCoreHttp::~LLAppCoreHttp() +{ + delete mRequest; + mRequest = NULL; +} + + +void LLAppCoreHttp::init() +{ + LLCore::HttpStatus status = LLCore::HttpRequest::createService(); + if (! status) + { + LL_ERRS("Init") << "Failed to initialize HTTP services. Reason: " + << status.toString() + << LL_ENDL; + } + + // Point to our certs or SSH/https: will fail on connect + status = LLCore::HttpRequest::setPolicyGlobalOption(LLCore::HttpRequest::GP_CA_FILE, + gDirUtilp->getCAFile()); + if (! status) + { + LL_ERRS("Init") << "Failed to set CA File for HTTP services. Reason: " + << status.toString() + << LL_ENDL; + } + + // Establish HTTP Proxy. "LLProxy" is a special string which directs + // the code to use LLProxy::applyProxySettings() to establish any + // HTTP or SOCKS proxy for http operations. + status = LLCore::HttpRequest::setPolicyGlobalOption(LLCore::HttpRequest::GP_LLPROXY, 1); + if (! status) + { + LL_ERRS("Init") << "Failed to set HTTP proxy for HTTP services. Reason: " + << status.toString() + << LL_ENDL; + } + + // Tracing levels for library & libcurl (note that 2 & 3 are beyond spammy): + // 0 - None + // 1 - Basic start, stop simple transitions + // 2 - libcurl CURLOPT_VERBOSE mode with brief lines + // 3 - with partial data content + status = LLCore::HttpRequest::setPolicyGlobalOption(LLCore::HttpRequest::GP_TRACE, 0); + + // Setup default policy and constrain if directed to + mPolicyDefault = LLCore::HttpRequest::DEFAULT_POLICY_ID; + static const std::string texture_concur("TextureFetchConcurrency"); + if (gSavedSettings.controlExists(texture_concur)) + { + U32 concur(llmin(gSavedSettings.getU32(texture_concur), U32(12))); + + if (concur > 0) + { + LLCore::HttpStatus status; + status = LLCore::HttpRequest::setPolicyClassOption(mPolicyDefault, + LLCore::HttpRequest::CP_CONNECTION_LIMIT, + concur); + if (! status) + { + LL_WARNS("Init") << "Unable to set texture fetch concurrency. Reason: " + << status.toString() + << LL_ENDL; + } + else + { + LL_INFOS("Init") << "Application settings overriding default texture fetch concurrency. New value: " + << concur + << LL_ENDL; + } + } + } + + // Kick the thread + status = LLCore::HttpRequest::startThread(); + if (! status) + { + LL_ERRS("Init") << "Failed to start HTTP servicing thread. Reason: " + << status.toString() + << LL_ENDL; + } + + mRequest = new LLCore::HttpRequest; +} + + +void LLAppCoreHttp::requestStop() +{ + llassert_always(mRequest); + + mStopHandle = mRequest->requestStopThread(this); + if (LLCORE_HTTP_HANDLE_INVALID != mStopHandle) + { + mStopRequested = LLTimer::getTotalSeconds(); + } +} + + +void LLAppCoreHttp::cleanup() +{ + if (LLCORE_HTTP_HANDLE_INVALID == mStopHandle) + { + // Should have been started already... + requestStop(); + } + + if (LLCORE_HTTP_HANDLE_INVALID == mStopHandle) + { + LL_WARNS("Cleanup") << "Attempting to cleanup HTTP services without thread shutdown" + << LL_ENDL; + } + else + { + while (! mStopped && LLTimer::getTotalSeconds() < (mStopRequested + MAX_THREAD_WAIT_TIME)) + { + mRequest->update(200000); + ms_sleep(50); + } + if (! mStopped) + { + LL_WARNS("Cleanup") << "Attempting to cleanup HTTP services with thread shutdown incomplete" + << LL_ENDL; + } + } + + delete mRequest; + mRequest = NULL; + + LLCore::HttpStatus status = LLCore::HttpRequest::destroyService(); + if (! status) + { + LL_WARNS("Cleanup") << "Failed to shutdown HTTP services, continuing. Reason: " + << status.toString() + << LL_ENDL; + } +} + + +void LLAppCoreHttp::onCompleted(LLCore::HttpHandle, LLCore::HttpResponse *) +{ + mStopped = true; +} diff --git a/indra/newview/llappcorehttp.h b/indra/newview/llappcorehttp.h new file mode 100644 index 0000000000..241d73ad52 --- /dev/null +++ b/indra/newview/llappcorehttp.h @@ -0,0 +1,86 @@ +/** + * @file llappcorehttp.h + * @brief Singleton initialization/shutdown class for llcorehttp library + * + * $LicenseInfo:firstyear=2012&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef _LL_APP_COREHTTP_H_ +#define _LL_APP_COREHTTP_H_ + + +#include "httprequest.h" +#include "httphandler.h" +#include "httpresponse.h" + + +// This class manages the lifecyle of the core http library. +// Slightly different style than traditional code but reflects +// the use of handler classes and light-weight interface +// object instances of the new libraries. To be used +// as a singleton and static construction is fine. +class LLAppCoreHttp : public LLCore::HttpHandler +{ +public: + LLAppCoreHttp(); + ~LLAppCoreHttp(); + + // Initialize the LLCore::HTTP library creating service classes + // and starting the servicing thread. Caller is expected to do + // other initializations (SSL mutex, thread hash function) appropriate + // for the application. + void init(); + + // Request that the servicing thread stop servicing requests, + // release resource references and stop. Request is asynchronous + // and @see cleanup() will perform a limited wait loop for this + // request to stop the thread. + void requestStop(); + + // Terminate LLCore::HTTP library services. Caller is expected + // to have made a best-effort to shutdown the servicing thread + // by issuing a requestThreadStop() and waiting for completion + // notification that the stop has completed. + void cleanup(); + + // Notification when the stop request is complete. + virtual void onCompleted(LLCore::HttpHandle handle, LLCore::HttpResponse * response); + + // Retrieve the policy class for default operations. + int getPolicyDefault() const + { + return mPolicyDefault; + } + +private: + static const F64 MAX_THREAD_WAIT_TIME; + +private: + LLCore::HttpRequest * mRequest; + LLCore::HttpHandle mStopHandle; + F64 mStopRequested; + bool mStopped; + int mPolicyDefault; +}; + + +#endif // _LL_APP_COREHTTP_H_ diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 0549a972e1..f8ee1a477f 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -215,10 +215,6 @@ #include "llmachineid.h" #include "llmainlooprepeater.h" -// LLCore::HTTP -#include "httpcommon.h" -#include "httprequest.h" -#include "httphandler.h" // *FIX: These extern globals should be cleaned up. // The globals either represent state/config/resource-storage of either @@ -334,53 +330,6 @@ static std::string gLaunchFileOnQuit; // Used on Win32 for other apps to identify our window (eg, win_setup) const char* const VIEWER_WINDOW_CLASSNAME = "Second Life"; -namespace -{ - -// This class manages the lifecyle of the core http library. -// Slightly different style than traditional code but reflects -// the use of handler classes and light-weight interface -// object instances of the new libraries. To be used -// as a singleton and static construction is fine. -class CoreHttp : public LLCore::HttpHandler -{ -public: - CoreHttp(); - ~CoreHttp(); - - // Initialize the LLCore::HTTP library creating service classes - // and starting the servicing thread. Caller is expected to do - // other initializations (SSL mutex, thread hash function) appropriate - // for the application. - void init(); - - // Request that the servicing thread stop servicing requests, - // release resource references and stop. - void requestStop(); - - // Terminate LLCore::HTTP library services. Caller is expected - // to have made a best-effort to shutdown the servicing thread - // by issuing a requestThreadStop() and waiting for completion - // notification that the stop has completed. - void cleanup(); - - // Notification when the stop request is complete. - virtual void onCompleted(LLCore::HttpHandle handle, LLCore::HttpResponse * response); - -private: - static const F64 MAX_THREAD_WAIT_TIME; - -private: - LLCore::HttpRequest * mRequest; - LLCore::HttpHandle mStopHandle; - F64 mStopRequested; - bool mStopped; -}; - -CoreHttp coreHttpLib; - -} // end anonymous namespace - //-- LLDeferredTaskList ------------------------------------------------------ /** @@ -775,8 +724,9 @@ bool LLAppViewer::init() LLViewerStatsRecorder::initClass(); #endif - // Initialize the non-LLCurl libcurl library - coreHttpLib.init(); + // Initialize the non-LLCurl libcurl library. Should be called + // before consumers (LLTextureFetch). + mAppCoreHttp.init(); // *NOTE:Mani - LLCurl::initClass is not thread safe. // Called before threads are created. @@ -1915,7 +1865,7 @@ bool LLAppViewer::cleanup() // Delete workers first // shotdown all worker threads before deleting them in case of co-dependencies - coreHttpLib.requestStop(); + mAppCoreHttp.requestStop(); sTextureFetch->shutdown(); sTextureCache->shutdown(); sImageDecodeThread->shutdown(); @@ -2000,7 +1950,7 @@ bool LLAppViewer::cleanup() LLCurl::cleanupClass(); // Non-LLCurl libcurl library - coreHttpLib.cleanup(); + mAppCoreHttp.cleanup(); // If we're exiting to launch an URL, do that here so the screen // is at the right resolution before we launch IE. @@ -5298,132 +5248,3 @@ void LLAppViewer::metricsSend(bool enable_reporting) gViewerAssetStatsMain->reset(); } -namespace -{ - -const F64 CoreHttp::MAX_THREAD_WAIT_TIME(10.0); - -CoreHttp::CoreHttp() - : mRequest(NULL), - mStopHandle(LLCORE_HTTP_HANDLE_INVALID), - mStopRequested(0.0), - mStopped(false) -{} - - -CoreHttp::~CoreHttp() -{ - delete mRequest; - mRequest = NULL; -} - - -void CoreHttp::init() -{ - LLCore::HttpStatus status = LLCore::HttpRequest::createService(); - if (! status) - { - LL_ERRS("Init") << "Failed to initialize HTTP services. Reason: " - << status.toString() - << LL_ENDL; - } - - // Point to our certs or SSH/https: will fail on connect - status = LLCore::HttpRequest::setPolicyGlobalOption(LLCore::HttpRequest::GP_CA_FILE, - gDirUtilp->getCAFile()); - if (! status) - { - LL_ERRS("Init") << "Failed to set CA File for HTTP services. Reason: " - << status.toString() - << LL_ENDL; - } - - // Establish HTTP Proxy. "LLProxy" is a special string which directs - // the code to use LLProxy::applyProxySettings() to establish any - // HTTP or SOCKS proxy for http operations. - status = LLCore::HttpRequest::setPolicyGlobalOption(LLCore::HttpRequest::GP_LLPROXY, 1); - if (! status) - { - LL_ERRS("Init") << "Failed to set HTTP proxy for HTTP services. Reason: " - << status.toString() - << LL_ENDL; - } - - // Tracing levels for library & libcurl (note that 2 & 3 are beyond spammy): - // 0 - None - // 1 - Basic start, stop simple transitions - // 2 - libcurl CURLOPT_VERBOSE mode with brief lines - // 3 - with partial data content - status = LLCore::HttpRequest::setPolicyGlobalOption(LLCore::HttpRequest::GP_TRACE, 0); - - // Kick the thread - status = LLCore::HttpRequest::startThread(); - if (! status) - { - LL_ERRS("Init") << "Failed to start HTTP servicing thread. Reason: " - << status.toString() - << LL_ENDL; - } - - mRequest = new LLCore::HttpRequest; -} - - -void CoreHttp::requestStop() -{ - llassert_always(mRequest); - - mStopHandle = mRequest->requestStopThread(this); - if (LLCORE_HTTP_HANDLE_INVALID != mStopHandle) - { - mStopRequested = LLTimer::getTotalSeconds(); - } -} - - -void CoreHttp::cleanup() -{ - if (LLCORE_HTTP_HANDLE_INVALID == mStopHandle) - { - // Should have been started already... - requestStop(); - } - - if (LLCORE_HTTP_HANDLE_INVALID == mStopHandle) - { - LL_WARNS("Cleanup") << "Attempting to cleanup HTTP services without thread shutdown" - << LL_ENDL; - } - else - { - while (! mStopped && LLTimer::getTotalSeconds() < (mStopRequested + MAX_THREAD_WAIT_TIME)) - { - mRequest->update(200000); - ms_sleep(50); - } - if (! mStopped) - { - LL_WARNS("Cleanup") << "Attempting to cleanup HTTP services with thread shutdown incomplete" - << LL_ENDL; - } - } - - delete mRequest; - mRequest = NULL; - - LLCore::HttpStatus status = LLCore::HttpRequest::destroyService(); - if (! status) - { - LL_WARNS("Cleanup") << "Failed to shutdown HTTP services, continuing. Reason: " - << status.toString() - << LL_ENDL; - } -} - - -void CoreHttp::onCompleted(LLCore::HttpHandle, LLCore::HttpResponse *) -{ - mStopped = true; -} - -} // end anonymous namespace diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h index f7d019ccba..a694ea9fe6 100644 --- a/indra/newview/llappviewer.h +++ b/indra/newview/llappviewer.h @@ -31,6 +31,7 @@ #include "llcontrol.h" #include "llsys.h" // for LLOSInfo #include "lltimer.h" +#include "llappcorehttp.h" class LLCommandLineParser; class LLFrameTimer; @@ -173,6 +174,9 @@ public: // Metrics policy helper statics. static void metricsUpdateRegion(U64 region_handle); static void metricsSend(bool enable_reporting); + + // llcorehttp init/shutdown/config information. + LLAppCoreHttp & getAppCoreHttp() { return mAppCoreHttp; } protected: virtual bool initWindow(); // Initialize the viewer's window. @@ -270,6 +274,9 @@ private: boost::scoped_ptr<LLUpdaterService> mUpdater; + // llcorehttp library init/shutdown helper + LLAppCoreHttp mAppCoreHttp; + //--------------------------------------------- //*NOTE: Mani - legacy updater stuff // Still useable? diff --git a/indra/newview/lltexturefetch.cpp b/indra/newview/lltexturefetch.cpp index 51d57ccf68..b5586d1250 100755 --- a/indra/newview/lltexturefetch.cpp +++ b/indra/newview/lltexturefetch.cpp @@ -868,7 +868,7 @@ LLTextureFetchWorker::LLTextureFetchWorker(LLTextureFetch* fetcher, mMetricsStartTime(0), mHttpHandle(LLCORE_HTTP_HANDLE_INVALID), mHttpBufferArray(NULL), - mHttpPolicyClass(LLCore::HttpRequest::DEFAULT_POLICY_ID), + mHttpPolicyClass(mFetcher->mHttpPolicyClass), mHttpActive(false), mHttpReplySize(0U), mHttpReplyOffset(0U), @@ -2302,6 +2302,7 @@ LLTextureFetch::LLTextureFetch(LLTextureCache* cache, LLImageDecodeThread* image mHttpOptions(NULL), mHttpHeaders(NULL), mHttpMetricsHeaders(NULL), + mHttpPolicyClass(LLCore::HttpRequest::DEFAULT_POLICY_ID), mHttpSemaphore(HTTP_REQUESTS_IN_QUEUE_HIGH_WATER), mTotalCacheReadCount(0U), mTotalCacheWriteCount(0U), @@ -2324,6 +2325,7 @@ LLTextureFetch::LLTextureFetch(LLTextureCache* cache, LLImageDecodeThread* image mHttpHeaders->mHeaders.push_back("Accept: image/x-j2c"); mHttpMetricsHeaders = new LLCore::HttpHeaders; mHttpMetricsHeaders->mHeaders.push_back("Content-Type: application/llsd+xml"); + mHttpPolicyClass = LLAppViewer::instance()->getAppCoreHttp().getPolicyDefault(); } LLTextureFetch::~LLTextureFetch() @@ -3631,7 +3633,6 @@ bool TFReqSendMetrics::doWork(LLTextureFetch * fetcher) { static const U32 report_priority(1); - static const int report_policy_class(LLCore::HttpRequest::DEFAULT_POLICY_ID); static LLCore::HttpHandler * const handler(fetcher->isQAMode() || true ? &stats_handler : NULL); if (! gViewerAssetStatsThread1) @@ -3671,7 +3672,7 @@ TFReqSendMetrics::doWork(LLTextureFetch * fetcher) LLCore::BufferArrayStream bas(ba); LLSDSerialize::toXML(merged_llsd, bas); - fetcher->getHttpRequest().requestPost(report_policy_class, + fetcher->getHttpRequest().requestPost(fetcher->getPolicyClass(), report_priority, mCapsURL, ba, @@ -3797,7 +3798,7 @@ LLTextureFetchDebugger::LLTextureFetchDebugger(LLTextureFetch* fetcher, LLTextur mTextureCache(cache), mImageDecodeThread(imagedecodethread), mHttpHeaders(NULL), - mHttpPolicyClass(LLCore::HttpRequest::DEFAULT_POLICY_ID) + mHttpPolicyClass(fetcher->getPolicyClass()) { init(); } diff --git a/indra/newview/lltexturefetch.h b/indra/newview/lltexturefetch.h index 54ffeda8df..115e471bc9 100644 --- a/indra/newview/lltexturefetch.h +++ b/indra/newview/lltexturefetch.h @@ -164,6 +164,9 @@ public: // Threads: T* LLCore::HttpRequest & getHttpRequest() { return *mHttpRequest; } + // Threads: T* + LLCore::HttpRequest::policy_t getPolicyClass() const { return mHttpPolicyClass; } + // Return a pointer to the shared metrics headers definition. // Does not increment the reference count, caller is required // to do that to hold a reference for any length of time. @@ -339,10 +342,11 @@ private: // Interfaces and objects into the core http library used // to make our HTTP requests. These replace the various // LLCurl interfaces used in the past. - LLCore::HttpRequest * mHttpRequest; // Ttf - LLCore::HttpOptions * mHttpOptions; // Ttf - LLCore::HttpHeaders * mHttpHeaders; // Ttf - LLCore::HttpHeaders * mHttpMetricsHeaders; // Ttf + LLCore::HttpRequest * mHttpRequest; // Ttf + LLCore::HttpOptions * mHttpOptions; // Ttf + LLCore::HttpHeaders * mHttpHeaders; // Ttf + LLCore::HttpHeaders * mHttpMetricsHeaders; // Ttf + LLCore::HttpRequest::policy_t mHttpPolicyClass; // T* // We use a resource semaphore to keep HTTP requests in // WAIT_HTTP_RESOURCE2 if there aren't sufficient slots in the |