Twisted and libtorrent - do I need to worry about blocking?

I am studying creating a multi-protocol application using twisted. One of these protocols is bittorrent. Since libtorrent is a fairly complete implementation, and its python bindings seem to be a good choice. Now the question is:

  • When using libtorrent with twisted, do I need to worry about blocking?
  • Does the layer of the libtorrent network (using boost.asio, an asynchronous network loop) affect the twisted era?
  • Should I start a libtorrent session in a thread or set up a project with multiple processes?
+4
source share
1 answer

I can answer some of these questions.

all libtorrents logic, including network and disk I / O, runs in separate threads. Thus, in the end, the problem of “blocking” is not so great. Assuming you mean libtorrent functions that are not returned immediately.

Some operations are guaranteed to be returned immediately, functions that do not return any state or information. However, the functions that do return something must be synchronized with the Libtorrent of the main thread, and if it is under heavy load (especially when embedding in debug mode with invariant checks and without optimization) this synchronization can be noticeable, especially when manufacturing many of them , and often.

There are ways to use libtorrent that are more asynchronous in nature, and continuous efforts are made to minimize the need for synchronized functions. For example, instead of requesting the status of all torrents individually, you can subscribe to torrent status updates. Asynchronous notifications are returned via pop_alerts ().

Will it interfere with the twisted epic; I can’t say for sure, but this does not seem very likely.

I do not think that it is very necessary to interact with libtorrent through a different level of threads, since all work is already being done in separate threads.

+2
source

All Articles