Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.14] Slow coroutine step execution: DownloadManager.create_session() because of ltsession.load_state(lt_state) #8060

Closed
kozlovsky opened this issue Jun 10, 2024 · 2 comments · Fixed by #8112
Assignees

Comments

@kozlovsky
Copy link
Contributor

https://sentry.tribler.org/organizations/tribler/issues/2798/events/491a11cdad524e96956ff63bf12f943a/

Slow coroutine execution: 18.317 seconds, 
<Task pending name='Task-9' coro=<Component.start() running at src\<relief>\core\components\component.py:42> cb=[gather.<locals>._done_callback() at C:\Users\<relief>\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py:751]>, 
Traceback (most recent call last):, 
  File "src\<relief>\core\start_core.py", line 206, in run_core (function started 22.815 seconds ago), 
  File "src\<relief>\core\start_core.py", line 169, in run_tribler_core_session (function started 21.971 seconds ago), 
  File "C:\Users\<relief>\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 603, in run_until_complete (function started 21.928 seconds ago), 
  File "C:\Users\<relief>\AppData\Local\Programs\Python\Python38\lib\asyncio\windows_events.py", line 316, in run_forever (function started 21.928 seconds ago), 
  File "C:\Users\<relief>\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 570, in run_forever (function started 21.928 seconds ago), 
  File "C:\Users\<relief>\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 1859, in _run_once (function started 18.317 seconds ago), 
  File "src\<relief>\core\utilities\slow_coro_detection\patch.py", line 37, in patched_handle_run (function started 18.317 seconds ago), 
  File "C:\Users\<relief>\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 81, in _run (function started 18.317 seconds ago), 
  File "src\<relief>\core\components\component.py", line 42, in start (function started 18.317 seconds ago), 
  File "src\<relief>\core\components\libtorrent\libtorrent_component.py", line 31, in run (function started 18.317 seconds ago), 
  File "src\<relief>\core\components\libtorrent\download_manager\download_manager.py", line 150, in initialize (function started 18.316 seconds ago), 
  File "src\<relief>\core\components\libtorrent\download_manager\download_manager.py", line 340, in get_session (function started 18.316 seconds ago), 
  File "src\<relief>\core\components\libtorrent\download_manager\download_manager.py", line 310, in create_session (function started 18.316 seconds ago)

Here:

    def create_session(self, hops=0, store_listen_port=True):
        ...
        # Set listen port & start the DHT
        if hops == 0:
            ltsession.listen_on(libtorrent_port, libtorrent_port + 10)
            if libtorrent_port != ltsession.listen_port() and store_listen_port:
                self.config.port = ltsession.listen_port()
            try:
                with open(self.state_dir / LTSTATE_FILENAME, 'rb') as fp:
                    lt_state = bdecode_compat(fp.read())
                if lt_state is not None:
                    ltsession.load_state(lt_state)  # line 310
                ...

It looks like load_state can be very slow, we should consider calling it outside of the asyncio event loop.

Copy link

Sentry issue: TRIBLER-1QR

@qstokkink qstokkink self-assigned this Aug 22, 2024
@qstokkink
Copy link
Contributor

I'll switch over self.ltsessions: dict[int, lt.session] = {} to self.ltsessions: dict[int, Future[lt.session]] = {} and schedule each create_session on a thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants