azmq icon indicating copy to clipboard operation
azmq copied to clipboard

Match asio support for futures and coroutines

Open ahundt opened this issue 10 years ago • 4 comments
trafficstars

There are a few items from asio I was hoping to use that don't appear to be supported yet, unless I am using things incorrectly. Thanks for taking a look!

Coroutine

asio coroutine + spawn overview asio spawn reference

I saw spawn exists in actor.hpp, but that appears to be for a different purpose, unless I misunderstood.

Here is an example I tried to create based of the asio echo_server.cpp

Futures

asio futures overview asio futures example

ahundt avatar Feb 27 '15 21:02 ahundt

You are correct, azmq::actor::spawn is something entirely different from Asio's stackful coroutines. They are equivalent to czmq's actors.

I have an experimental 'typed actor' implementation (similar to Akka's typed actors) built on Asio's stackless (not the stackful variety of asio::spawn) coroutines but it is not ready for general use.

It is definitely possible to use Asio coroutines though with azmq, there is just no explicit support yet for doing so. I also am not a particularly enthusiastic fan of stackful coroutines (they have their uses interfacing with legacy code, but they are very resource intensive).

I have discussed supporting Asio's extensible machinery for futures a bit with Chris Kohlhoff (he originally suggested it) for azmq. I even have an open issue on GitHub for it already. The problem is they are ill suited to my personal use cases. Futures are significantly more expensive than the call-back, though with the proposed .then() extensions this can be mitigated somewhat. So I haven't yet had 'proper motivation' to do the work.

On Friday, February 27, 2015, Andrew Hundt [email protected] wrote:

There are a few items from asio I was hoping to use that don't appear to be supported yet, unless I am using things incorrectly. Thanks for taking a look! Coroutine

asio spawn overview http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/overview/core/spawn.html asio spawn reference http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/reference/spawn.html

I saw spawn exists in actor.hpp, but that appears to be for a different purpose, unless I misunderstood.

Here is an example I tried to create based of the asio echo_server.cpp https://gist.github.com/ahundt/a436d1506b282664ec9a Futures

[asio futures overview] http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/overview/cpp2011/futures.html asio futures example http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/example/cpp11/futures/daytime_client.cpp

— Reply to this email directly or view it on GitHub https://github.com/zeromq/azmq/issues/67.

rodgert avatar Feb 27 '15 21:02 rodgert

Ok, those are good reasons not to use it. I was using this as an opportunity to learn some new C++11 code, but ended up with a slightly more conventional implementation for my test. If the conventional implementation is known to be faster as of now then I will stick to that! At least now with C++11 I can often put the handler inline, it makes the code much simpler and easier to follow!

Perhaps on the boost mailing list I (or you if you use the list and would prefer it) should suggest adding a note about the performance concerns of these new features on the documentation.

ahundt avatar Feb 28 '15 16:02 ahundt

Chris Kohlhoff (Asio's author) is well aware of these issues. He has presented a couple of papers to SG1 (C++ Standards Committee concurrency study group) about the performance of callbacks vs futures. We have also discussed at length (and will likely continue to discuss/debate) the relative merits of stackless vs stackful coroutines as we look at providing support for them in the language and standard library.

I will ask Chris if maybe it is worth including some of the material from his previous presentations in the Asio docs.

On Saturday, February 28, 2015, Andrew Hundt [email protected] wrote:

Ok, those are good reasons not to use it. I was using this as an opportunity to learn some new C++11 code, but ended up with a slightly more conventional implementation for my test. If the conventional implementation is known to be faster as of now then I will stick to that!

Perhaps on the boost mailing list I (or you if you use the list and would prefer it) should suggest adding a note about the performance concerns of these new features on the documentation.

— Reply to this email directly or view it on GitHub https://github.com/zeromq/azmq/issues/67#issuecomment-76532960.

rodgert avatar Feb 28 '15 17:02 rodgert

see #195

aboseley avatar Jan 05 '22 09:01 aboseley