]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #3959 "by default, disable prefetch for lightweight builds" -- fixed.
authorJordan Lee <jordan@transmissionbt.com>
Mon, 31 Jan 2011 23:35:10 +0000 (23:35 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Mon, 31 Jan 2011 23:35:10 +0000 (23:35 +0000)
User jusid reports prefetch causes load on his NMT to jump from <1 to 3-4. He requests a way to disable prefetch, and suggests that prefetch be disabled by default on lightweight builds.  This commit adds a new settings.json key, "prefetch-enabled", which defaults to "true" on standard builds and "false" when compiled with --enable-lightweight.

libtransmission/peer-msgs.c
libtransmission/session.c
libtransmission/session.h
libtransmission/transmission.h

index 1cc87c66d9c60e888422b5cbc7f6f64f32ff06f9..70d4c5a0424d5d93ae265663b78122ec3bc067e5 100644 (file)
@@ -1196,6 +1196,9 @@ prefetchPieces( tr_peermsgs *msgs )
 {
     int i;
 
+    if( !getSession(msgs)->isPrefetchEnabled )
+        return;
+
     /* Maintain 12 prefetched blocks per unchoked peer */
     for( i=msgs->prefetchCount; i<msgs->peer->pendingReqsToClient && i<12; ++i )
     {
index 0c1b18b8149c0098589b4f0e5ee0b4fdeb50248d..d00f8812afe190a933c87136ef8b8fc9b0988b65 100644 (file)
 
 enum
 {
-    SAVE_INTERVAL_SECS = 360,
-
 #ifdef TR_LIGHTWEIGHT
-    DEFAULT_CACHE_SIZE_MB = 2
+    DEFAULT_CACHE_SIZE_MB = 2,
+    DEFAULT_PREFETCH_ENABLED = FALSE,
 #else
-    DEFAULT_CACHE_SIZE_MB = 4
+    DEFAULT_CACHE_SIZE_MB = 4,
+    DEFAULT_PREFETCH_ENABLED = TRUE,
 #endif
+    SAVE_INTERVAL_SECS = 360
 };
 
 
@@ -334,6 +335,7 @@ tr_sessionGetDefaultSettings( const char * configDir UNUSED, tr_benc * d )
     tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED,              TRUE );
     tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING,          TRUE );
     tr_bencDictAddInt ( d, TR_PREFS_KEY_PREALLOCATION,            TR_PREALLOCATE_SPARSE );
+    tr_bencDictAddBool( d, TR_PREFS_KEY_PREFETCH_ENABLED,         DEFAULT_PREFETCH_ENABLED );
     tr_bencDictAddReal( d, TR_PREFS_KEY_RATIO,                    2.0 );
     tr_bencDictAddBool( d, TR_PREFS_KEY_RATIO_ENABLED,            FALSE );
     tr_bencDictAddBool( d, TR_PREFS_KEY_RENAME_PARTIAL_FILES,     TRUE );
@@ -398,6 +400,7 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d )
     tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED,              s->isPexEnabled );
     tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING,          tr_sessionIsPortForwardingEnabled( s ) );
     tr_bencDictAddInt ( d, TR_PREFS_KEY_PREALLOCATION,            s->preallocationMode );
+    tr_bencDictAddInt ( d, TR_PREFS_KEY_PREFETCH_ENABLED,         s->isPrefetchEnabled );
     tr_bencDictAddReal( d, TR_PREFS_KEY_RATIO,                    s->desiredRatio );
     tr_bencDictAddBool( d, TR_PREFS_KEY_RATIO_ENABLED,            s->isRatioLimited );
     tr_bencDictAddBool( d, TR_PREFS_KEY_RENAME_PARTIAL_FILES,     tr_sessionIsIncompleteFileNamingEnabled( s ) );
@@ -779,6 +782,8 @@ sessionSetImpl( void * vdata )
         tr_sessionSetDeleteSource( session, boolVal );
 
     /* files and directories */
+    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PREFETCH_ENABLED, &boolVal ) )
+        session->isPrefetchEnabled = boolVal;
     if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PREALLOCATION, &i ) )
         session->preallocationMode = i;
     if( tr_bencDictFindStr( settings, TR_PREFS_KEY_DOWNLOAD_DIR, &str ) )
index 792768aa1b694d368d8b2280018ecf7a0a969e0f..0be846d937fb4f2fe442e45ff6ecf2038aa4ce13 100644 (file)
@@ -91,6 +91,7 @@ struct tr_session
     tr_bool                      isDHTEnabled;
     tr_bool                      isLPDEnabled;
     tr_bool                      isBlocklistEnabled;
+    tr_bool                      isPrefetchEnabled;
     tr_bool                      isTorrentDoneScriptEnabled;
     tr_bool                      isClosed;
     tr_bool                      useLazyBitfield;
index 033740d67f9d8d4c7a8750d4373bcb6c469a2444..69c0a3c17cbc063f2529a377cce133fbf3fbd60e 100644 (file)
@@ -162,6 +162,7 @@ const char* tr_getDefaultDownloadDir( void );
 #define TR_PREFS_KEY_MAX_CACHE_SIZE_MB             "cache-size-mb"
 #define TR_PREFS_KEY_DHT_ENABLED                   "dht-enabled"
 #define TR_PREFS_KEY_LPD_ENABLED                   "lpd-enabled"
+#define TR_PREFS_KEY_PREFETCH_ENABLED              "prefetch-enabled"
 #define TR_PREFS_KEY_DOWNLOAD_DIR                  "download-dir"
 #define TR_PREFS_KEY_ENCRYPTION                    "encryption"
 #define TR_PREFS_KEY_IDLE_LIMIT                    "idle-seeding-limit"