diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 2a9d76cc9..c9fea0e68 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -379,6 +379,7 @@ Session::Session(QObject *parent) , m_checkingMemUsage(BITTORRENT_SESSION_KEY("CheckingMemUsageSize"), 32) , m_diskCacheSize(BITTORRENT_SESSION_KEY("DiskCacheSize"), -1) , m_diskCacheTTL(BITTORRENT_SESSION_KEY("DiskCacheTTL"), 60) + , m_diskQueueSize(BITTORRENT_SESSION_KEY("DiskQueueSize"), (1024 * 1024)) , m_useOSCache(BITTORRENT_SESSION_KEY("UseOSCache"), true) #ifdef Q_OS_WIN , m_coalesceReadWriteEnabled(BITTORRENT_SESSION_KEY("CoalesceReadWrite"), true) @@ -468,6 +469,7 @@ Session::Session(QObject *parent) , m_peerTurnover(BITTORRENT_SESSION_KEY("PeerTurnover"), 4) , m_peerTurnoverCutoff(BITTORRENT_SESSION_KEY("PeerTurnoverCutOff"), 90) , m_peerTurnoverInterval(BITTORRENT_SESSION_KEY("PeerTurnoverInterval"), 300) + , m_requestQueueSize(BITTORRENT_SESSION_KEY("RequestQueueSize"), 500) , m_bannedIPs("State/BannedIPs" , QStringList() , [](const QStringList &value) @@ -1330,6 +1332,8 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack) settingsPack.set_int(lt::settings_pack::peer_turnover_cutoff, peerTurnoverCutoff()); settingsPack.set_int(lt::settings_pack::peer_turnover_interval, peerTurnoverInterval()); + settingsPack.set_int(lt::settings_pack::max_out_request_queue, requestQueueSize()); + settingsPack.set_int(lt::settings_pack::aio_threads, asyncIOThreads()); #ifdef QBT_USES_LIBTORRENT2 settingsPack.set_int(lt::settings_pack::hashing_threads, hashingThreads()); @@ -1345,6 +1349,8 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack) settingsPack.set_int(lt::settings_pack::cache_expiry, diskCacheTTL()); #endif + settingsPack.set_int(lt::settings_pack::max_queued_disk_bytes, diskQueueSize()); + lt::settings_pack::io_buffer_mode_t mode = useOSCache() ? lt::settings_pack::enable_os_cache : lt::settings_pack::disable_os_cache; settingsPack.set_int(lt::settings_pack::disk_io_read_mode, mode); @@ -3259,6 +3265,20 @@ void Session::setPeerTurnoverInterval(const int val) configureDeferred(); } +int Session::requestQueueSize() const +{ + return m_requestQueueSize; +} + +void Session::setRequestQueueSize(const int val) +{ + if (val == m_requestQueueSize) + return; + + m_requestQueueSize = val; + configureDeferred(); +} + int Session::asyncIOThreads() const { return std::clamp(m_asyncIOThreads.get(), 1, 1024); @@ -3357,6 +3377,20 @@ void Session::setDiskCacheTTL(const int ttl) } } +qint64 Session::diskQueueSize() const +{ + return m_diskQueueSize; +} + +void Session::setDiskQueueSize(const qint64 size) +{ + if (size == m_diskQueueSize) + return; + + m_diskQueueSize = size; + configureDeferred(); +} + bool Session::useOSCache() const { return m_useOSCache; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 7c9aeb1d6..b478f1a31 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -343,11 +343,13 @@ namespace BitTorrent bool announceToAllTiers() const; void setAnnounceToAllTiers(bool val); int peerTurnover() const; - void setPeerTurnover(int num); + void setPeerTurnover(int val); int peerTurnoverCutoff() const; - void setPeerTurnoverCutoff(int num); + void setPeerTurnoverCutoff(int val); int peerTurnoverInterval() const; - void setPeerTurnoverInterval(int num); + void setPeerTurnoverInterval(int val); + int requestQueueSize() const; + void setRequestQueueSize(int val); int asyncIOThreads() const; void setAsyncIOThreads(int num); int hashingThreads() const; @@ -360,6 +362,8 @@ namespace BitTorrent void setDiskCacheSize(int size); int diskCacheTTL() const; void setDiskCacheTTL(int ttl); + qint64 diskQueueSize() const; + void setDiskQueueSize(qint64 size); bool useOSCache() const; void setUseOSCache(bool use); bool isCoalesceReadWriteEnabled() const; @@ -679,6 +683,7 @@ namespace BitTorrent CachedSettingValue m_checkingMemUsage; CachedSettingValue m_diskCacheSize; CachedSettingValue m_diskCacheTTL; + CachedSettingValue m_diskQueueSize; CachedSettingValue m_useOSCache; CachedSettingValue m_coalesceReadWriteEnabled; CachedSettingValue m_usePieceExtentAffinity; @@ -760,6 +765,7 @@ namespace BitTorrent CachedSettingValue m_peerTurnover; CachedSettingValue m_peerTurnoverCutoff; CachedSettingValue m_peerTurnoverInterval; + CachedSettingValue m_requestQueueSize; CachedSettingValue m_bannedIPs; CachedSettingValue m_resumeDataStorageType; #if defined(Q_OS_WIN) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index da61f6672..8df517624 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -106,6 +106,7 @@ namespace DISK_CACHE, DISK_CACHE_TTL, #endif + DISK_QUEUE_SIZE, OS_CACHE, #ifndef QBT_USES_LIBTORRENT2 COALESCE_RW, @@ -140,6 +141,7 @@ namespace PEER_TURNOVER, PEER_TURNOVER_CUTOFF, PEER_TURNOVER_INTERVAL, + REQUEST_QUEUE_SIZE, ROW_COUNT }; @@ -212,6 +214,8 @@ void AdvancedSettings::saveAdvancedSettings() session->setDiskCacheSize(m_spinBoxCache.value()); session->setDiskCacheTTL(m_spinBoxCacheTTL.value()); #endif + // Disk queue size + session->setDiskQueueSize(m_spinBoxDiskQueueSize.value() * 1024); // Enable OS cache session->setUseOSCache(m_checkBoxOsCache.isChecked()); #ifndef QBT_USES_LIBTORRENT2 @@ -319,6 +323,8 @@ void AdvancedSettings::saveAdvancedSettings() session->setPeerTurnover(m_spinBoxPeerTurnover.value()); session->setPeerTurnoverCutoff(m_spinBoxPeerTurnoverCutoff.value()); session->setPeerTurnoverInterval(m_spinBoxPeerTurnoverInterval.value()); + // Maximum outstanding requests to a single peer + session->setRequestQueueSize(m_spinBoxRequestQueueSize.value()); } #ifndef QBT_USES_LIBTORRENT2 @@ -498,6 +504,13 @@ void AdvancedSettings::loadAdvancedSettings() addRow(DISK_CACHE_TTL, (tr("Disk cache expiry interval") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#cache_expiry", "(?)")) , &m_spinBoxCacheTTL); #endif + // Disk queue size + m_spinBoxDiskQueueSize.setMinimum(1); + m_spinBoxDiskQueueSize.setMaximum(std::numeric_limits::max()); + m_spinBoxDiskQueueSize.setValue(session->diskQueueSize() / 1024); + m_spinBoxDiskQueueSize.setSuffix(tr(" KiB")); + addRow(DISK_QUEUE_SIZE, (tr("Disk queue size") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#max_queued_disk_bytes", "(?)")) + , &m_spinBoxDiskQueueSize); // Enable OS cache m_checkBoxOsCache.setChecked(session->useOSCache()); addRow(OS_CACHE, (tr("Enable OS cache") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#disk_io_write_mode", "(?)")) @@ -759,6 +772,12 @@ void AdvancedSettings::loadAdvancedSettings() m_spinBoxPeerTurnoverInterval.setValue(session->peerTurnoverInterval()); addRow(PEER_TURNOVER_INTERVAL, (tr("Peer turnover disconnect interval") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#peer_turnover", "(?)")) , &m_spinBoxPeerTurnoverInterval); + // Maximum outstanding requests to a single peer + m_spinBoxRequestQueueSize.setMinimum(1); + m_spinBoxRequestQueueSize.setMaximum(std::numeric_limits::max()); + m_spinBoxRequestQueueSize.setValue(session->requestQueueSize()); + addRow(REQUEST_QUEUE_SIZE, (tr("Maximum outstanding requests to a single peer") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#max_out_request_queue", "(?)")) + , &m_spinBoxRequestQueueSize); } template diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index ec28c398f..bb93fcb4c 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -58,11 +58,11 @@ private: void loadAdvancedSettings(); template void addRow(int row, const QString &text, T *widget); - QSpinBox m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, + QSpinBox m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, m_spinBoxDiskQueueSize, m_spinBoxSaveResumeDataInterval, m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, m_spinBoxPeerToS, m_spinBoxListRefresh, m_spinBoxTrackerPort, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark, m_spinBoxSendBufferWatermarkFactor, m_spinBoxConnectionSpeed, m_spinBoxSocketBacklogSize, m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout, - m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval; + m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval, m_spinBoxRequestQueueSize; QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts, m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxReannounceWhenAddressChanged, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus, m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers, diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index db1d999df..8a514c158 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -306,6 +306,8 @@ void AppController::preferencesAction() // Disk write cache data["disk_cache"] = session->diskCacheSize(); data["disk_cache_ttl"] = session->diskCacheTTL(); + // Disk queue size + data["disk_queue_size"] = session->diskQueueSize(); // Enable OS cache data["enable_os_cache"] = session->useOSCache(); // Coalesce reads & writes @@ -358,6 +360,8 @@ void AppController::preferencesAction() data["peer_turnover"] = session->peerTurnover(); data["peer_turnover_cutoff"] = session->peerTurnoverCutoff(); data["peer_turnover_interval"] = session->peerTurnoverInterval(); + // Maximum outstanding requests to a single peer + data["request_queue_size"] = session->requestQueueSize(); setResult(data); } @@ -777,6 +781,9 @@ void AppController::setPreferencesAction() session->setDiskCacheSize(it.value().toInt()); if (hasKey("disk_cache_ttl")) session->setDiskCacheTTL(it.value().toInt()); + // Disk queue size + if (hasKey("disk_queue_size")) + session->setDiskQueueSize(it.value().toLongLong()); // Enable OS cache if (hasKey("enable_os_cache")) session->setUseOSCache(it.value().toBool()); @@ -863,6 +870,9 @@ void AppController::setPreferencesAction() session->setPeerTurnoverCutoff(it.value().toInt()); if (hasKey("peer_turnover_interval")) session->setPeerTurnoverInterval(it.value().toInt()); + // Maximum outstanding requests to a single peer + if (hasKey("request_queue_size")) + session->setRequestQueueSize(it.value().toInt()); // Save preferences pref->apply(); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 05daca124..5446cec3f 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -44,7 +44,7 @@ #include "base/utils/net.h" #include "base/utils/version.h" -inline const Utils::Version API_VERSION {2, 8, 6}; +inline const Utils::Version API_VERSION {2, 8, 7}; class APIController; class WebApplication; diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index acd3c36c8..b7dcc576d 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1012,6 +1012,14 @@   QBT_TR(s)QBT_TR[CONTEXT=OptionsDialog] + + + + + +   QBT_TR(KiB)QBT_TR[CONTEXT=OptionsDialog] + + @@ -1254,6 +1262,14 @@   s + + + + + + + + @@ -1931,6 +1947,7 @@ $('outstandMemoryWhenCheckingTorrents').setProperty('value', pref.checking_memory_use); $('diskCache').setProperty('value', pref.disk_cache); $('diskCacheExpiryInterval').setProperty('value', pref.disk_cache_ttl); + $('diskQueueSize').setProperty('value', (pref.disk_queue_size / 1024)); $('enableOSCache').setProperty('checked', pref.enable_os_cache); $('coalesceReadsAndWrites').setProperty('checked', pref.enable_coalesce_read_write); $('pieceExtentAffinity').setProperty('checked', pref.enable_piece_extent_affinity); @@ -1962,6 +1979,7 @@ $('peerTurnover').setProperty('value', pref.peer_turnover); $('peerTurnoverCutoff').setProperty('value', pref.peer_turnover_cutoff); $('peerTurnoverInterval').setProperty('value', pref.peer_turnover_interval); + $('requestQueueSize').setProperty('value', pref.request_queue_size); } } }).send(); @@ -2326,6 +2344,7 @@ settings.set('checking_memory_use', $('outstandMemoryWhenCheckingTorrents').getProperty('value')); settings.set('disk_cache', $('diskCache').getProperty('value')); settings.set('disk_cache_ttl', $('diskCacheExpiryInterval').getProperty('value')); + settings.set('disk_queue_size', ($('diskQueueSize').getProperty('value') * 1024)); settings.set('enable_os_cache', $('enableOSCache').getProperty('checked')); settings.set('enable_coalesce_read_write', $('coalesceReadsAndWrites').getProperty('checked')); settings.set('enable_piece_extent_affinity', $('pieceExtentAffinity').getProperty('checked')); @@ -2357,6 +2376,7 @@ settings.set('peer_turnover', $('peerTurnover').getProperty('value')); settings.set('peer_turnover_cutoff', $('peerTurnoverCutoff').getProperty('value')); settings.set('peer_turnover_interval', $('peerTurnoverInterval').getProperty('value')); + settings.set('request_queue_size', $('requestQueueSize').getProperty('value')); // Send it to qBT const json_str = JSON.encode(settings);