简体   繁体   中英

Asynchronous single-threaded vs synchronous multi-threaded for network protocol design?

Our team is implementing a secure multi-layered peer-to-peer protocol which establishes connections between nodes over multiple intermediate 'hops' using Boost/C++.

We are currently locked in a debate on how to implement the protocol design, namely, as a asynchronous single-threaded or synchronous multi-threaded architecture.

I do not want to bias the question by enumerating pros and cons but I am keenly interested in the experience of the StackOverFlow community in such matters and which approach they would favour?

I realise that this is an open question so ideally the answer would not be based on anecdotal evidence but derived from some empirical or analytical basis.

I would recommend asynchronous for two reasons:

  • you don't need to deal with thread interactions, which are always a minefield of bugs;
  • you can use the Boost.Asio library to handle all the low-level scheduling, connection management, etc. This also makes it easy to use more than one thread if you need to for performance reasons.

Synchronous could be more straightforward if the connections are independent, so that no threads have to share mutable state. If you can't make that guarantee, and be sure that it will not change in the future, then I would choose asynchronous.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM