From: Jordan Lee Date: Mon, 31 Jan 2011 23:35:10 +0000 (+0000) Subject: (trunk libT) #3959 "by default, disable prefetch for lightweight builds" -- fixed. X-Git-Tag: 2.20b4~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f5fc4ade74109d8dff987f9e653d4ae9ddc5012;p=transmission (trunk libT) #3959 "by default, disable prefetch for lightweight builds" -- fixed. 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. --- diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 1cc87c66d..70d4c5a04 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -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; ipeer->pendingReqsToClient && i<12; ++i ) { diff --git a/libtransmission/session.c b/libtransmission/session.c index 0c1b18b81..d00f8812a 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -53,13 +53,14 @@ 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 ) ) diff --git a/libtransmission/session.h b/libtransmission/session.h index 792768aa1..0be846d93 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -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; diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 033740d67..69c0a3c17 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -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"