From b4bfdd6f7aa5b3c709d4133808517bc835c8084b Mon Sep 17 00:00:00 2001 From: Anton Bershanskiy Date: Sat, 10 Oct 2020 08:07:04 +0300 Subject: [PATCH] Add option for hashing_threads, use 10 asyc IO threads Add option for setting lt::settings_pack::hashing_threads introduced by libtorrent 2.0. It has no effect for earlier libtorrent versions. Use 10 async IO threads, as per #11461. Closes #11461. --- src/base/bittorrent/session.cpp | 20 +++++++++++++++++++- src/base/bittorrent/session.h | 3 +++ src/gui/advancedsettings.cpp | 17 +++++++++++++++++ src/gui/advancedsettings.h | 2 ++ src/webui/api/appcontroller.cpp | 5 +++++ src/webui/www/private/views/preferences.html | 10 ++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 06ff1003e..97a0ad94f 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -329,7 +329,8 @@ Session::Session(QObject *parent) , m_IPFilterFile(BITTORRENT_SESSION_KEY("IPFilter")) , m_announceToAllTrackers(BITTORRENT_SESSION_KEY("AnnounceToAllTrackers"), false) , m_announceToAllTiers(BITTORRENT_SESSION_KEY("AnnounceToAllTiers"), true) - , m_asyncIOThreads(BITTORRENT_SESSION_KEY("AsyncIOThreadsCount"), 4) + , m_asyncIOThreads(BITTORRENT_SESSION_KEY("AsyncIOThreadsCount"), 10) + , m_hashingThreads(BITTORRENT_SESSION_KEY("HashingThreadsCount"), 2) , m_filePoolSize(BITTORRENT_SESSION_KEY("FilePoolSize"), 40) , m_checkingMemUsage(BITTORRENT_SESSION_KEY("CheckingMemUsageSize"), 32) #if (LIBTORRENT_VERSION_NUM >= 10206) @@ -1269,6 +1270,9 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack) settingsPack.set_int(lt::settings_pack::peer_turnover_interval, peerTurnoverInterval()); settingsPack.set_int(lt::settings_pack::aio_threads, asyncIOThreads()); +#if (LIBTORRENT_VERSION_NUM >= 20000) + settingsPack.set_int(lt::settings_pack::hashing_threads, hashingThreads()); +#endif settingsPack.set_int(lt::settings_pack::file_pool_size, filePoolSize()); const int checkingMemUsageSize = checkingMemUsage() * 64; @@ -3030,6 +3034,20 @@ void Session::setAsyncIOThreads(const int num) configureDeferred(); } +int Session::hashingThreads() const +{ + return qBound(1, m_hashingThreads.value(), 1024); +} + +void Session::setHashingThreads(const int num) +{ + if (num == m_hashingThreads) + return; + + m_hashingThreads = num; + configureDeferred(); +} + int Session::filePoolSize() const { return m_filePoolSize; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 5935d06cf..de5d92fe4 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -342,6 +342,8 @@ namespace BitTorrent void setPeerTurnoverInterval(int num); int asyncIOThreads() const; void setAsyncIOThreads(int num); + int hashingThreads() const; + void setHashingThreads(int num); int filePoolSize() const; void setFilePoolSize(int size); int checkingMemUsage() const; @@ -651,6 +653,7 @@ namespace BitTorrent CachedSettingValue m_announceToAllTrackers; CachedSettingValue m_announceToAllTiers; CachedSettingValue m_asyncIOThreads; + CachedSettingValue m_hashingThreads; CachedSettingValue m_filePoolSize; CachedSettingValue m_checkingMemUsage; CachedSettingValue m_diskCacheSize; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index f9cb408b7..10563ac88 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -85,6 +85,9 @@ namespace // libtorrent section LIBTORRENT_HEADER, ASYNC_IO_THREADS, +#if (LIBTORRENT_VERSION_NUM >= 20000) + HASHING_THREADS, +#endif FILE_POOL_SIZE, CHECKING_MEM_USAGE, #if (LIBTORRENT_VERSION_NUM < 20000) @@ -187,6 +190,10 @@ void AdvancedSettings::saveAdvancedSettings() #endif // Async IO threads session->setAsyncIOThreads(m_spinBoxAsyncIOThreads.value()); +#if (LIBTORRENT_VERSION_NUM >= 20000) + // Hashing threads + session->setHashingThreads(m_spinBoxHashingThreads.value()); +#endif // File pool size session->setFilePoolSize(m_spinBoxFilePoolSize.value()); // Checking Memory Usage @@ -409,6 +416,16 @@ void AdvancedSettings::loadAdvancedSettings() m_spinBoxAsyncIOThreads.setValue(session->asyncIOThreads()); addRow(ASYNC_IO_THREADS, (tr("Asynchronous I/O threads") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#aio_threads", "(?)")) , &m_spinBoxAsyncIOThreads); + +#if (LIBTORRENT_VERSION_NUM >= 20000) + // Hashing threads + m_spinBoxHashingThreads.setMinimum(1); + m_spinBoxHashingThreads.setMaximum(1024); + m_spinBoxHashingThreads.setValue(session->hashingThreads()); + addRow(HASHING_THREADS, (tr("Hashing threads") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#hashing_threads", "(?)")) + , &m_spinBoxHashingThreads); +#endif + // File pool size m_spinBoxFilePoolSize.setMinimum(1); m_spinBoxFilePoolSize.setMaximum(std::numeric_limits::max()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 24a703a07..857ceb6c0 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -77,6 +77,8 @@ private: #if (LIBTORRENT_VERSION_NUM < 20000) QSpinBox m_spinBoxCache, m_spinBoxCacheTTL; QCheckBox m_checkBoxCoalesceRW; +#else + QSpinBox m_spinBoxHashingThreads; #endif // OS dependent settings diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index cb1525ae1..5967d26d9 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -277,6 +277,8 @@ void AppController::preferencesAction() // libtorrent preferences // Async IO threads data["async_io_threads"] = session->asyncIOThreads(); + // Hashing threads + data["hashing_threads"] = session->hashingThreads(); // File pool size data["file_pool_size"] = session->filePoolSize(); // Checking memory usage @@ -701,6 +703,9 @@ void AppController::setPreferencesAction() // Async IO threads if (hasKey("async_io_threads")) session->setAsyncIOThreads(it.value().toInt()); + // Hashing threads + if (hasKey("hashing_threads")) + session->setHashingThreads(it.value().toInt()); // File pool size if (hasKey("file_pool_size")) session->setFilePoolSize(it.value().toInt()); diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 035b46d8b..edbb642d5 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -943,6 +943,14 @@ + + + + + + + + @@ -1871,6 +1879,7 @@ $('resolvePeerCountries').setProperty('checked', pref.resolve_peer_countries); // libtorrent section $('asyncIOThreads').setProperty('value', pref.async_io_threads); + $('hashingThreads').setProperty('value', pref.hashing_threads); $('filePoolSize').setProperty('value', pref.file_pool_size); $('outstandMemoryWhenCheckingTorrents').setProperty('value', pref.checking_memory_use); $('diskCache').setProperty('value', pref.disk_cache); @@ -2257,6 +2266,7 @@ // libtorrent section settings.set('async_io_threads', $('asyncIOThreads').getProperty('value')); + settings.set('hashing_threads', $('hashingThreads').getProperty('value')); settings.set('file_pool_size', $('filePoolSize').getProperty('value')); settings.set('checking_memory_use', $('outstandMemoryWhenCheckingTorrents').getProperty('value')); settings.set('disk_cache', $('diskCache').getProperty('value'));