Skip to content

Commit

Permalink
Merge pull request #1566 from LipuFei/fix_tracker_checking
Browse files Browse the repository at this point in the history
Change Tracker Checking interval mechanism
  • Loading branch information
whirm committed Jul 28, 2015
2 parents dc5a263 + a3040cf commit 84e0d09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions Tribler/Core/Modules/tracker_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


MAX_TRACKER_FAILURES = 5
DEAD_TRACKER_RETRY_INTERVAL = 60 # A "dead" tracker will be retired every 60 seconds
TRACKER_RETRY_INTERVAL = 60 # A "dead" tracker will be retired every 60 seconds


class TrackerManager(object):
Expand All @@ -22,7 +22,7 @@ def __init__(self, session):
self._max_tracker_failures = MAX_TRACKER_FAILURES

# A "dead" tracker will be retired every this amount of time (in seconds)
self._dead_tracker_retry_interval = DEAD_TRACKER_RETRY_INTERVAL
self._tracker_retry_interval = TRACKER_RETRY_INTERVAL

# we use round-robin for automatic tracker checking.
# this index points to the tracker we are going to check next.
Expand Down Expand Up @@ -121,12 +121,11 @@ def should_check_tracker(self, tracker_url):
"""
current_time = int(time.time())

tracker_info = self._tracker_dict.get(tracker_url, {u'is_alive': True, u'last_check': 0})
if tracker_info[u'is_alive']:
return True
tracker_info = self._tracker_dict.get(tracker_url, {u'is_alive': True, u'last_check': 0, u'failures': 0})

interval = current_time - tracker_info[u'last_check']
return interval >= self._dead_tracker_retry_interval
# this_interval = retry_interval * 2^failures
next_check_time = tracker_info[u'last_check'] + self._tracker_retry_interval * (2**tracker_info[u'failures'])
return next_check_time <= current_time

@call_on_reactor_thread
def get_next_tracker_for_auto_check(self):
Expand Down
2 changes: 1 addition & 1 deletion Tribler/Core/TorrentChecker/torrent_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def _create_session_for_request(self, infohash, tracker_url):

# before creating a new session, check if the tracker is alive
if not self._session.lm.tracker_manager.should_check_tracker(tracker_url):
self._logger.warn(u"skipping dead tracker %s", tracker_url)
self._logger.warn(u"skipping recently failed tracker %s", tracker_url)
return

session = None
Expand Down

0 comments on commit 84e0d09

Please sign in to comment.