From 17da4cf57aadcf1987b48af298d8b2742089a35c Mon Sep 17 00:00:00 2001
From: Monty Brandenberg <monty@lindenlab.com>
Date: Fri, 27 Jun 2014 17:25:39 -0400
Subject: [PATCH] Cleanup and tuning.  Use a consistent index on some
 initialization data so their isn't an opportunity for gaps over overruns
 (init_data). Start some preliminary tweaking of policy class numbers.  It
 looks like I can easily drop the default connection count to '4' and still
 hit the throttles.  Did some experiments running pipeline deeper which was
 mostly fine for textures but tended to slow meshes.  Reason uncertain but a
 depth of '5' seems generally healthy for mesh.  I had one run of 52.6S with a
 theoretical minimum of 51.2S. That's as good as I've ever seen.

---
 indra/newview/llappcorehttp.cpp    | 41 +++++++++++++++++-------------
 indra/newview/llmeshrepository.cpp |  7 ++++-
 indra/newview/lltexturefetch.cpp   |  2 ++
 3 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/indra/newview/llappcorehttp.cpp b/indra/newview/llappcorehttp.cpp
index deda0ccb41c..d097f18d61c 100755
--- a/indra/newview/llappcorehttp.cpp
+++ b/indra/newview/llappcorehttp.cpp
@@ -42,9 +42,9 @@
 const F64 LLAppCoreHttp::MAX_THREAD_WAIT_TIME(10.0);
 const long LLAppCoreHttp::PIPELINING_DEPTH(5L);
 
+//  Default and dynamic values for classes
 static const struct
 {
-	LLAppCoreHttp::EAppPolicy	mPolicy;
 	U32							mDefault;
 	U32							mMin;
 	U32							mMax;
@@ -52,40 +52,40 @@ static const struct
 	bool						mPipelined;
 	std::string					mKey;
 	const char *				mUsage;
-} init_data[] =					//  Default and dynamic values for classes
+} init_data[LLAppCoreHttp::AP_COUNT] =
 {
-	{
-		LLAppCoreHttp::AP_DEFAULT,			8,		8,		8,		0,		false,
+	{ // AP_DEFAULT
+		8,		8,		8,		0,		false,
 		"",
 		"other"
 	},
-	{
-		LLAppCoreHttp::AP_TEXTURE,			8,		1,		12,		0,		true,	
+	{ // AP_TEXTURE
+		4,		1,		12,		0,		true,	
 		"TextureFetchConcurrency",
 		"texture fetch"
 	},
-	{
-		LLAppCoreHttp::AP_MESH1,			32,		1,		128,	100,	false,
+	{ // AP_MESH1
+		32,		1,		128,	100,	false,
 		"MeshMaxConcurrentRequests",
 		"mesh fetch"
 	},
-	{
-		LLAppCoreHttp::AP_MESH2,			8,		1,		32,		100,	true,	
+	{ // AP_MESH2
+		4,		1,		32,		100,	true,	
 		"Mesh2MaxConcurrentRequests",
 		"mesh2 fetch"
 	},
-	{
-		LLAppCoreHttp::AP_LARGE_MESH,		2,		1,		8,		0,		false,
+	{ // AP_LARGE_MESH
+		2,		1,		8,		0,		false,
 		"",
 		"large mesh fetch"
 	},
-	{
-		LLAppCoreHttp::AP_UPLOADS,			2,		1,		8,		0,		false,
+	{ // AP_UPLOADS 
+		2,		1,		8,		0,		false,
 		"",
 		"asset upload"
 	},
-	{
-		LLAppCoreHttp::AP_LONG_POLL,		32,		32,		32,		0,		false,
+	{ // AP_LONG_POLL
+		32,		32,		32,		0,		false,
 		"",
 		"long poll"
 	}
@@ -173,9 +173,10 @@ void LLAppCoreHttp::init()
 	mHttpClasses[AP_DEFAULT].mPolicy = LLCore::HttpRequest::DEFAULT_POLICY_ID;
 
 	// Setup additional policies based on table and some special rules
+	llassert(LL_ARRAY_SIZE(init_data) == AP_COUNT);
 	for (int i(0); i < LL_ARRAY_SIZE(init_data); ++i)
 	{
-		const EAppPolicy app_policy(init_data[i].mPolicy);
+		const EAppPolicy app_policy(static_cast<EAppPolicy>(i));
 
 		if (AP_DEFAULT == app_policy)
 		{
@@ -301,7 +302,7 @@ void LLAppCoreHttp::refreshSettings(bool initial)
 	
 	for (int i(0); i < LL_ARRAY_SIZE(init_data); ++i)
 	{
-		const EAppPolicy app_policy(init_data[i].mPolicy);
+		const EAppPolicy app_policy(static_cast<EAppPolicy>(i));
 
 		if (initial)
 		{
@@ -326,6 +327,10 @@ void LLAppCoreHttp::refreshSettings(bool initial)
 			if (mPipelined && init_data[i].mPipelined)
 			{
 				// Pipelining election is currently static (init-time).
+				// Making it dynamic isn't too hard in the SL code but verifying
+				// that libcurl handles the on-to-off transition while holding
+				// outstanding requests is something that should be tested.
+				
 				status = LLCore::HttpRequest::setStaticPolicyOption(LLCore::HttpRequest::PO_PIPELINING_DEPTH,
 																	mHttpClasses[app_policy].mPolicy,
 																	PIPELINING_DEPTH,
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index c91ae975ead..74eb6015f23 100755
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -338,14 +338,17 @@ static LLFastTimer::DeclareTimer FTM_MESH_FETCH("Mesh Fetch");
 LLMeshRepository gMeshRepo;
 
 const S32 MESH_HEADER_SIZE = 4096;                      // Important:  assumption is that headers fit in this space
+
 const S32 REQUEST_HIGH_WATER_MIN = 32;					// Limits for GetMesh regions
 const S32 REQUEST_HIGH_WATER_MAX = 150;					// Should remain under 2X throttle
 const S32 REQUEST_LOW_WATER_MIN = 16;
 const S32 REQUEST_LOW_WATER_MAX = 75;
+
 const S32 REQUEST2_HIGH_WATER_MIN = 32;					// Limits for GetMesh2 regions
 const S32 REQUEST2_HIGH_WATER_MAX = 100;
 const S32 REQUEST2_LOW_WATER_MIN = 16;
 const S32 REQUEST2_LOW_WATER_MAX = 50;
+
 const U32 LARGE_MESH_FETCH_THRESHOLD = 1U << 21;		// Size at which requests goes to narrow/slow queue
 const long SMALL_MESH_XFER_TIMEOUT = 120L;				// Seconds to complete xfer, small mesh downloads
 const long LARGE_MESH_XFER_TIMEOUT = 600L;				// Seconds to complete xfer, large downloads
@@ -3203,7 +3206,9 @@ void LLMeshRepository::notifyLoadedMeshes()
 		// we'll increase this.  See llappcorehttp and llcorehttp for
 		// discussion on connection strategies.
 		LLAppCoreHttp & app_core_http(LLAppViewer::instance()->getAppCoreHttp());
-		S32 scale(app_core_http.isPipelined(LLAppCoreHttp::AP_MESH2) ? 10 : 5);
+		S32 scale(app_core_http.isPipelined(LLAppCoreHttp::AP_MESH2)
+				  ? (2 * LLAppCoreHttp::PIPELINING_DEPTH)
+				  : 5);
 
 		LLMeshRepoThread::sMaxConcurrentRequests = gSavedSettings.getU32("Mesh2MaxConcurrentRequests");
 		LLMeshRepoThread::sRequestHighWater = llclamp(scale * S32(LLMeshRepoThread::sMaxConcurrentRequests),
diff --git a/indra/newview/lltexturefetch.cpp b/indra/newview/lltexturefetch.cpp
index ee11e7b47b3..ecaf5f8d061 100755
--- a/indra/newview/lltexturefetch.cpp
+++ b/indra/newview/lltexturefetch.cpp
@@ -2516,6 +2516,8 @@ LLTextureFetch::LLTextureFetch(LLTextureCache* cache, LLImageDecodeThread* image
 	mHttpPolicyClass = app_core_http.getPolicy(LLAppCoreHttp::AP_TEXTURE);
 	if (app_core_http.isPipelined(LLAppCoreHttp::AP_TEXTURE))
 	{
+		// Init-time election that will have to change for
+		// support of dynamic changes to the pipelining enable flag.
 		mHttpHighWater = HTTP_PIPE_REQUESTS_HIGH_WATER;
 		mHttpLowWater = HTTP_PIPE_REQUESTS_LOW_WATER;
 	}
-- 
GitLab