From b07b208a4aaf6f0c060dfe8099a9172b6ba08ac9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 5 Apr 2015 19:35:58 +0000 Subject: [PATCH] rate limit how often recalculate_auto_managed can be called (it's expensive) --- include/libtorrent/aux_/session_impl.hpp | 4 ++++ src/session_impl.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index af5e5e521..ffc7ee25c 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -976,6 +976,10 @@ namespace libtorrent // to decide which ones to choke/unchoke time_point m_last_choke; + // the last time we recalculated which torrents should be started + // and stopped (only the auto managed ones) + time_point m_last_auto_manage; + #ifndef TORRENT_NO_DEPRECATE // the time when the next rss feed needs updating time_point m_next_rss_update; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index c2c26fd83..d3655e5de 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -390,6 +390,7 @@ namespace aux { , m_last_tick(m_created) , m_last_second_tick(m_created - milliseconds(900)) , m_last_choke(m_created) + , m_last_auto_manage(m_created) #ifndef TORRENT_NO_DEPRECATE , m_next_rss_update(min_time()) #endif @@ -3494,6 +3495,7 @@ retry: { INVARIANT_CHECK; + m_last_auto_manage = time_now_hires(); m_need_auto_manage = false; if (is_paused()) return; @@ -5918,6 +5920,13 @@ retry: { if (m_pending_auto_manage || m_abort) return; + // we we recalculated auto-managed torrents less than a second ago, + // put it off one second. + if (time_now_hires() - m_last_auto_manage < seconds(1)) + { + m_auto_manage_time_scaler = 0; + return; + } m_pending_auto_manage = true; m_need_auto_manage = true;