diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 05751452d..a01acf6f0 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -289,6 +289,12 @@ namespace aux { ~disk_io_thread(); #endif + enum + { + // every 4:th thread is a hash thread + hasher_thread_divisor = 4 + }; + void set_settings(settings_pack const* sett); void abort(bool wait); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 767c01a89..5d253292a 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -321,7 +321,7 @@ constexpr disk_job_flags_t disk_interface::cache_hit; int const num_threads = m_settings.get_int(settings_pack::aio_threads); // add one hasher thread for every three generic threads - int const num_hash_threads = num_threads / 4; + int const num_hash_threads = num_threads / hasher_thread_divisor; m_generic_threads.set_max_threads(num_threads - num_hash_threads); m_hash_threads.set_max_threads(num_hash_threads); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 0afd792b1..9009612ab 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2291,8 +2291,11 @@ bool is_downloading_state(int const st) / m_torrent_file->piece_length(); // if we only keep a single read operation in-flight at a time, we suffer // significant performance degradation. Always keep at least two jobs - // outstanding - if (num_outstanding < 2) num_outstanding = 2; + // outstanding per hasher thread + int const min_outstanding = 2 + * std::max(1, settings().get_int(settings_pack::aio_threads) + / disk_io_thread::hasher_thread_divisor); + if (num_outstanding < min_outstanding) num_outstanding = min_outstanding; // we might already have some outstanding jobs, if we were paused and // resumed quickly, before the outstanding jobs completed