Skip to content

Commit

Permalink
credit mining awareness of main downloading activity -flexible priority-
Browse files Browse the repository at this point in the history
  • Loading branch information
ardhipoetra committed Apr 5, 2016
1 parent 8dc00a1 commit cee0d5d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Tribler/Core/Libtorrent/LibtorrentDownloadImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ def create_engine_wrapper(self, lm_network_engine_wrapper_created_callback, psta

if not self.ltmgr or not dht_ok or not session_ok:
self._logger.info(u"LTMGR/DHT/session not ready, rescheduling create_engine_wrapper")

if tunnels_ready < 1:
tunnel_community.build_tunnels(self.get_hops())

self.session.lm.threadpool.call(5, self.create_engine_wrapper,
lm_network_engine_wrapper_created_callback, pstate,
initialdlstatus=initialdlstatus, share_mode=share_mode,
Expand Down Expand Up @@ -332,7 +336,7 @@ def set_vod_mode(self, enable=True):
self._logger.debug("LibtorrentDownloadImpl: going into VOD mode %s", filename)
else:
self.handle.set_sequential_download(False)
self.handle.set_priority(0)
self.handle.set_priority(30)
if self.get_vod_fileindex() >= 0:
self.set_byte_priority([(self.get_vod_fileindex(), 0, -1)], 1)

Expand Down
45 changes: 43 additions & 2 deletions Tribler/Policies/BoostingManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from Tribler.Main.vwxGUI.SearchGridManager import ChannelManager as cm

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s.%(msecs).03dZ-%(levelname)s-%(message)s",
datefmt="%Y%m%dT%H%M%S")
Expand Down Expand Up @@ -147,6 +147,8 @@ def __init__(self, session):
class BoostingManager(TaskManager):

__single = None
MULTIPLIER_DL = [0, 0.2, 0.6, 1, 1.5, 3]
DEFAULT_PRIORITY_TORRENT = 5

def __init__(self, session, utility=None, policy=SeederRatioPolicy, src_interval=20, sw_interval=20,
max_per_source=100, max_active=2):
Expand Down Expand Up @@ -395,7 +397,37 @@ def on_torrent_insert(self, source, infohash, torrent):
# logger.info("Got new torrent %s from %s", infohash.encode('hex'),
# source_str)

def _check_main_download(self, idx_multiplier):

total_cm_prio = sum([tr['download'].handle.status().priority or 0
for tr in self.torrents.values() if tr and tr.get('download', False) and
tr['download'].handle])

(hits_num, hits) = self.gui_util.library_manager.getHitsInCategory()

total_main_prio = sum([chn_tor.ds.get_download().handle.status().priority or 0
for chn_tor in hits if chn_tor and chn_tor.ds and chn_tor.ds.get_download().handle])

ret_cm_prio = total_cm_prio

self._logger.debug("totm %d totc %d retc %d",total_main_prio, total_cm_prio, ret_cm_prio)

# if main downloading not that much, we can continue as it is
# else, reduce priority
if total_main_prio >= total_cm_prio:
ret_cm_prio = total_cm_prio - self.MULTIPLIER_DL[idx_multiplier]*\
(total_main_prio-total_cm_prio)

return len([tr for tr in self.torrents.values() if tr and tr.get('download', False)]), ret_cm_prio

def scrape_trackers(self):

num_dl, total_prio_tor = self._check_main_download(3)

# 1 is the lowest priority we'd want to assign
new_prio = (total_prio_tor/float(num_dl) if num_dl else self.DEFAULT_PRIORITY_TORRENT) or 1


for infohash, torrent in self.torrents.iteritems():
tf = torrent['metainfo']

Expand Down Expand Up @@ -441,6 +473,13 @@ def _logtorrentpeer(status, lt_torrent):
print "----------------------"
# _logtorrentpeer(status, lt_torrent)


# change priority (reduce load on main downloading)
if new_prio and int(new_prio) != status.get_priority():
lt.set_priority(int(new_prio))
self._logger.info("Change priority %s from %d to %d", status.info_hash,
status.get_priority(),new_prio)

peer_list = []
for i in lt_torrent.get_peer_info():
peer = LibtorrentDownloadImpl.create_peerlist_data(i)
Expand Down Expand Up @@ -554,7 +593,7 @@ def do_start():

tobj['download'] = self.session.lm.add(tobj['metainfo'], dscfg, pstate=tobj.get('pstate', None),
hidden=True, share_mode=not preload, checkpoint_disabled=True)
tobj['download'].set_priority(tobj.get('prio', 1))
tobj['download'].set_priority(tobj.get('prio', self.DEFAULT_PRIORITY_TORRENT))

self.session.lm.threadpool.add_task_in_thread(do_start, 0)

Expand Down Expand Up @@ -705,6 +744,7 @@ def update_torrent_stats(self, torrent_infohash_str, seeding_stats):
else:
self.torrents[torrent_infohash_str]['last_seeding_stats'] = seeding_stats


class BoostingSource(object):

def __init__(self, session, tqueue, source, interval, max_torrents, callback):
Expand Down Expand Up @@ -740,6 +780,7 @@ def _update(self):
def getSource(self):
return self.source


class ChannelSource(BoostingSource):

def __init__(self, session, tqueue, dispersy_cid, interval, max_torrents, callback):
Expand Down
2 changes: 1 addition & 1 deletion logger.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ level=ERROR
handlers=default

[logger_TftpRequester]
level=DEBUG
level=ERROR
qualname=TftpRequester
handlers=default
propagate=0
Expand Down

0 comments on commit cee0d5d

Please sign in to comment.