qbittorrent / qBittorrent

qBittorrent BitTorrent client
https://www.qbittorrent.org
Other
28.23k stars 3.97k forks source link

Move "slow" torrents to the bottom of the Queue or Pause #14804

Open Dr4w opened 3 years ago

Dr4w commented 3 years ago

qBittorrent version: Nox 4.1.5 and 4.3.4.1 Operating System: Raspberry Pi OS (Linux) and Windows 10

Motivation

I know there is the "Do not count slow torrents in these limits" option, but that doesn't do what I'd like to actually do, as even tho it "skips" the slow torrents, it keeps them active and downloading, which for people (like me) who have a kinda slow download speed is not ideal as it "steal" bandwith from the fastest torrents, especially if these slow ones start to build up.

Feature Details

More information

I'd like to be able to have only 1 (or a selected amount) torrent actually downloading at the time, so that after the fastest ones are done, it reaches the bottom of the Queue and it can actually start the slow ones again.

ComodoHacker commented 3 years ago

There's an option called 'Do not count slow torrents in these limits' in Options/BitTorrent, with basically same effect. Wouldn't it be enough in your case?

Dr4w commented 3 years ago

There's an option called 'Do not count slow torrents in these limits' in Options/BitTorrent, with basically same effect. Wouldn't it be enough in your case?

Did you even read the main post? It's literally the first thing I wrote in the Motivation section.

itlezy commented 2 years ago

That's the thing @ComodoHacker , for some reason which is unclear to me and I'm trying to figure in libtorrent's behavior, it is that 'Stalled' torrents seem still to count as active downloads, but only when they are actually stalled. Torrents which instead have slow traffic, they are counted correctly as slow torrents.

For now, a fix as suggested by @Dr4w which I'm now testing is the following

Add to SpeedMonitor a boolean that tells if there're enough speed samples collected

bool SpeedMonitor::enoughSamples() {
    return (m_speedSamples.size() >= (MAX_SAMPLES - 1));
}

Then ensure to reset the SpeedMonitor when a torrent gets resumed by the queuing system

void TorrentImpl::handleTorrentResumedAlert(const lt::torrent_resumed_alert *p)
{
    // need to know when the torrent gets resumed by the queuing system,
    // so I can reset its stats and have a valid depth of samples to understand if it's actually stalled
    LogMsg(tr("Resuming torrent, reset stats: '%1'").arg(name()));

    m_speedMonitor.reset();
}

And finally, move to the bottom of the queue a torrent that is stalled

void TorrentImpl::updateState() {
...

        else {

            if (m_speedMonitor.enoughSamples()) {
                LogMsg(tr("Moving stalled torrent at the bottom of the queue \"%1\"").arg(name()));
                m_nativeHandle.queue_position_bottom();
            }

            m_state = TorrentState::StalledDownloading;
        }

This is just an initial proof of concept which I am now testing with a number of queued torrents

itlezy commented 2 years ago

After few attempts, I am evaluating along moving the stalled torrent to the end of the queue, to either pause it or resume it as forced download. The latter option looks good as the torrent is stalled, so it's unlikely it will actually generate much download traffic, but we give it a chance to complete in case sources will become available. It could also be possible to add a tag to ease the management of stalled downloads, as it usually are stalled due to a lack of sources to download from and many often are never able to actually complete.

void TorrentImpl::updateState() {
...

else {

    if (m_speedMonitor.enoughSamples()) {
        LogMsg(tr("Moving stalled torrent at the bottom of the queue \"%1\"").arg(name()));
        m_nativeHandle.queue_position_bottom();
        this->resume(BitTorrent::TorrentOperatingMode::Forced);
    }

    m_state = TorrentState::StalledDownloading;
}
pspot2 commented 1 year ago

After reading all the similar issues I could find, I think that fixing the functionality of "Do not count slow torrents in these limits" and making it work properly for stalled torrents seems to be the proper direction. The option could also be renamed to "Do not count slow/stalled torrents in these limits".

Similar issues: #14955 #17840 #18371