Skip to content

Commit

Permalink
start boosting manager if ready only -reduce startup load-
Browse files Browse the repository at this point in the history
  • Loading branch information
ardhipoetra committed Apr 22, 2016
1 parent ebafd6f commit 9949e2c
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions Tribler/Policies/BoostingManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
from Tribler.Core.TorrentChecker.session import MAX_TRACKER_MULTI_SCRAPE
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Core.Utilities import utilities
from Tribler.Core.exceptions import TriblerException
from Tribler.Core.simpledefs import DLSTATUS_SEEDING, NTFY_INSERT, NTFY_SCRAPE, NTFY_TORRENTS, NTFY_UPDATE
from Tribler.Main.Utility.GuiDBTuples import Torrent
from Tribler.Main.Utility.GuiDBHandler import startWorker
from Tribler.Main.globals import DefaultDownloadStartupConfig
from Tribler.Main.vwxGUI.GuiUtility import GUIUtility
from Tribler.Main.vwxGUI.SearchGridManager import ChannelManager
Expand All @@ -36,6 +38,7 @@
from Tribler.dispersy.taskmanager import TaskManager
from Tribler.dispersy.util import call_on_reactor_thread


from Tribler.Main.vwxGUI.SearchGridManager import ChannelManager as cm

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -730,6 +733,7 @@ class BoostingSource(object):
def __init__(self, session, tqueue, source, interval, max_torrents, callback):
self.session = session
self.session.lm.threadpool = tqueue
self.channelcast_db = session.lm.channelcast_db

self.torrents = {}
self.source = source
Expand All @@ -749,10 +753,27 @@ def __init__(self, session, tqueue, source, interval, max_torrents, callback):
if not self.gui_util.registered:
self.gui_util.register()


def kill_tasks(self):
self.session.lm.threadpool.cancel_pending_task(self.source)

def _load_if_ready(self, source):

nr_channels = self.channelcast_db.getNrChannels()
nr_connections = 0

for community in self.session.lm.dispersy.get_communities():
from Tribler.community.search.community import SearchCommunity
if isinstance(community, SearchCommunity):
nr_connections = community.get_nr_connections()

# condition example
if nr_channels > 100 and nr_connections > 5:
fun = self._load
else:
fun = self._load_if_ready

self.session.lm.threadpool.add_task(lambda src=source: fun(src), 15, task_name=str(self.source)+"_load")

def _load(self, source):
pass

Expand All @@ -771,14 +792,11 @@ def __init__(self, session, tqueue, dispersy_cid, interval, max_torrents, callba
self.channel_id = None

self.channel = None

self.channelcast_db = self.session.lm.channelcast_db

self.community = None
self.database_updated = True

self.session.add_observer(self._on_database_updated, NTFY_TORRENTS, [NTFY_INSERT, NTFY_UPDATE])
self.session.lm.threadpool.add_task(lambda cid=dispersy_cid: self._load(cid), 0, task_name=self.source)
self.session.lm.threadpool.add_task(lambda cid=dispersy_cid: self._load_if_ready(cid), 0, task_name=str(self.source)+"_load")

self.unavail_torrent = {}

Expand All @@ -790,7 +808,6 @@ def _load(self, dispersy_cid):
dispersy = self.session.get_dispersy_instance()

@call_on_reactor_thread

def join_community():
try:
self.community = dispersy.get_community(dispersy_cid, True)
Expand Down Expand Up @@ -831,10 +848,10 @@ def get_channel_id():
self.ready = True
except Exception,ex:
logger.info("Channel %s was not ready, waits for next interval (%d chn)", hexlify(self.source), len(dispersy.get_communities()))
self.session.lm.threadpool.add_task(lambda cid=self.source: self._load(cid), 10, task_name=self.source)
self.session.lm.threadpool.add_task(lambda cid=dispersy_cid: self._load_if_ready(cid), 0, task_name=str(self.source)+"_load")

def _check_tor(self):
from Tribler.Main.Utility.GuiDBHandler import startWorker

def doGui(delayedResult):
# wait here
requesttype = delayedResult.get(timeout=70)
Expand Down Expand Up @@ -924,7 +941,7 @@ def __init__(self, session, tqueue, rss_feed, interval, max_torrents, callback):

self.feed_handle = None

self.session.lm.threadpool.add_task(lambda feed=rss_feed: self._load(feed), 0, task_name=str(self.source)+"_load")
self.session.lm.threadpool.add_task(lambda feed=rss_feed: self._load_if_ready(feed), 0, task_name=str(self.source)+"_load")

self.title = ""
self.description = ""
Expand Down Expand Up @@ -1037,8 +1054,7 @@ class DirectorySource(BoostingSource):

def __init__(self, session, tqueue, directory, interval, max_torrents, callback):
BoostingSource.__init__(self, session, tqueue, directory, interval, max_torrents, callback)

self._load(directory)
self._load_if_ready(directory)

def _load(self, directory):
if os.path.isdir(directory):
Expand Down

0 comments on commit 9949e2c

Please sign in to comment.