Closed i94matjo closed 4 years ago
thanks for the PR! unfortunately: no, we don't want to expose/support a callback(-only) based API, and
future continuations causes thread creation explosion
why? AutobahnC++ is designed to allow single-threaded apps mainly .. it all depends on the specific boost/asio reactor used I guess ..
so I'd go for option 3.: use futures + single threaded app
Because that's the way boost continuations work, see for example boost::detail::future_async_continuation_shared_state::launch_continuation. So with a large number of futures this does not fly. We must not use continuation. That leaves us with a couple of other options though. We could use boost's when_all to bundle up futures and then continue, or do not use continuations at all or just skip the notification. If we don't want continuations and we can only wait for one future at a time per thread we'll need to queue the futures and wait for them one by one in order, possibly with a timeout. Then it's not truly asynchronous though which is kind of sad since we already have the truly asynchronous boost::asio::io_service as engine. But we'll make it work. Somehow... It's only during initialization this happens so we may not need to be fully asynchronous here. Thanks!
Not sure we're on the same page? To my knowledge, the thread on which a future is scheduled is determined by the launch policy / executor, eg:
boost::launch::deferred
should run on the same thread as the future submitting code.
this, combined with boost::wait_for_all
should then allow to process many futures on one thread.
decoupling the number of futures (being not yet complete) from the number of threads (discounting desire to parallelize workload) is one advantage of async programming IMO ...
probably, would be good to have an example https://github.com/crossbario/autobahn-cpp/issues/204 ..
would that work for you? demonstrate that useful work like multiple outstanding futures, waiting for a set of futures to complete etc can be done single threaded?
Perfect! Thanks a lot! We will use ideas from that one. Thanks for the quick reply!
great! pls post here or on #204 about your findings / results if possible - this ("single threaded async mode") is definitely sth we want to support, actually encourage for autobahnc++
OK, I'll try to explain why this pull request is needed. It all boils down to the use of futures. We have an embedded system with limited resources which does a lot of, mostly provides but this essentially accounts for everything, asynchronous calls. Using futures is not ideally here. We end up in two different scenarios: