Skip to content

Commit

Permalink
Reduce torrent checking intensity
Browse files Browse the repository at this point in the history
Also fixed some types
  • Loading branch information
qstokkink committed Aug 23, 2024
1 parent 8fd1051 commit 9537121
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/tribler/core/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def get_kwargs(self, session: Session) -> dict:
out["manager"] = UserActivityManager(TaskManager(), session, max_query_history)
return out


@precondition('session.config.get("versioning/enabled")')
class VersioningComponent(ComponentLauncher):
"""
Expand Down
9 changes: 6 additions & 3 deletions src/tribler/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
from tribler.core.socks5.server import Socks5Server

if TYPE_CHECKING:
from tribler.core.database.store import MetadataStore
from tribler.core.database.tribler_database import TriblerDatabase
from tribler.core.torrent_checker.torrent_checker import TorrentChecker
from tribler.tribler_config import TriblerConfigManager

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -113,9 +116,9 @@ def __init__(self, config: TriblerConfigManager) -> None:
self.rest_manager = RESTManager(self.config)

# Optional globals, set by components:
self.db = None
self.mds = None
self.torrent_checker = None
self.db: TriblerDatabase | None = None
self.mds: MetadataStore | None = None
self.torrent_checker: TorrentChecker | None = None

def register_launchers(self) -> None:
"""
Expand Down
4 changes: 2 additions & 2 deletions src/tribler/core/torrent_checker/torrent_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
TORRENT_SELECTION_INTERVAL = 10 # The interval for checking the health of a random torrent
MIN_TORRENT_CHECK_INTERVAL = 900 # How much time we should wait before checking a torrent again
TORRENT_CHECK_RETRY_INTERVAL = 30 # Interval when the torrent was successfully checked for the last time
MAX_TORRENTS_CHECKED_PER_SESSION = 50
MAX_TORRENTS_CHECKED_PER_SESSION = 5 # (5 random + 5 per tracker = 10 torrents) per 10 seconds

TORRENT_SELECTION_POOL_SIZE = 2 # How many torrents to check (popular or random) during periodic check
USER_CHANNEL_TORRENT_SELECTION_POOL_SIZE = 5 # How many torrents to check from user's channel during periodic check
Expand All @@ -57,7 +57,7 @@ class TorrentChecker(TaskManager):
A class to check the health of torrents.
"""

def __init__(self, # noqa: PLR0913
def __init__(self,
config: TriblerConfigManager,
download_manager: DownloadManager,
notifier: Notifier,
Expand Down
7 changes: 4 additions & 3 deletions src/tribler/core/user_activity/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, task_manager: TaskManager, session: Session, max_query_histor
self.queries: OrderedDict[str, typing.Set[InfoHash]] = OrderedDict()
self.max_query_history = max_query_history
self.database_manager: UserActivityLayer = session.db.user_activity
self.torrent_checker: TorrentChecker = session.torrent_checker
self.torrent_checker: TorrentChecker | None = session.torrent_checker
self.task_manager = task_manager

# Hook events
Expand Down Expand Up @@ -84,5 +84,6 @@ def check(self, infohash: bytes) -> None:
"""
Check the health of a given infohash.
"""
self.task_manager.register_anonymous_task("Check preferable torrent",
self.torrent_checker.check_torrent_health, infohash)
if self.torrent_checker:
self.task_manager.register_anonymous_task("Check preferable torrent",
self.torrent_checker.check_torrent_health, infohash)

0 comments on commit 9537121

Please sign in to comment.