Question

I am looking into building a multi-protocol application using twisted. One of those protocols is bittorrent. Since libtorrent is a fairly complete implementation and its python bindings seems to be a good choice. Now the question is:

  • When using libtorrent with twisted, do I need to worry about blocking?
  • Does the libtorrent networking layer (using boost.asio, a async networking loop) interfere with twisted epoll in any way?
  • Should I perhaps run the libtorrent session in a thread or target a multi-process application design?
Was it helpful?

Solution

I may be able to provide answers to some of those questions.

all of libtorrents logic, including networking and disk I/O is done in separate threads. So, over all, the concern of "blocking" is not that great. Assuming you mean libtorrent functions not returning immediately.

Some operations are guaranteed to return immediately, functions that don't return any state or information. However, functions that do return something, must synchronize with the libtorrent main thread, and if it is under heavy load (especially when built in debug mode with invariant checks and no optimization) this synchronization may be noticeable, especially when making many of them, and often.

There are ways to use libtorrent that are more asynchronous in nature, and there is an ongoing effort in minimizing the need for using functions that synchronize. For example, instead of querying the status of all torrents individually, one can subscribe to torrent status updates. Asynchronous notifications are returned via pop_alerts().

Whether it would interfere with twisted's epoll; I can't say for sure, but it doesn't seem very likely.

I don't think there's much need to interact with libtorrent via another layer of threads, since all of the work is already done in separate threads.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top