Open silver-ymz opened 1 year ago
Questsions:
Thoughts:
Initially, I believe adding support for asio
to make our async functionality usable would be a good idea. However, I'm uncertain as my knowledge of cpp is limited.
Helps:
@jiaoew1991 is a potential user of our async C++ binding. Would you be interested in providing us with some feedback on the support for async C++?
Hi @silver-ymz, this issue is a capability that we currently need. I think there are several points to consider:
The implementation of runtime and thread pool needs customization capabilities. In our scenario, we have requirements for adjusting concurrency and thread priority.
At the same time, we use folly
's thread pool. The cxx binding provides an abstraction for the runtime, so we can implement it internally based on folly's thread pool.
As a library, the C++ version should not be set too high since there may not be many users using C++20 😅
asio: We have used Boost as a dependency. So we can integrate asio runtime to expose our async API. This is the most common way and does not require importing more dependencies.
There are two alternatives to asio (boost or standalone). Standalone has C++20 stackless coroutine support and boost::
add stackfull coroutines (need boost::context
).
Reference: https://think-async.com/Asio/AsioAndBoostAsio.html
In cpp side, I come up with following ways:
std
: C++11 providesstd::async
andstd::future
, C++20 providescoroutine
. We can expose API compatible with the standard library. Cons: Maybe we need to limit cpp version to at least c++20.asio
: We have usedBoost
as a dependency. So we can integrate asio runtime to expose our async API. This is the most common way and does not require importing more dependencies.libevent
,libuv
.tokio
, likehyper
C API. This provides maximum flexibility and performance.Solutions of some popular cloud sdk:
Gcp
usestd
, but havn't completed until now.AWS
andAzure
use custom async runtime.I prefer to use
std
, because it provides more flexibility thanasio
。And compared with custom runtime,std
is easier to use and less expensive to learn.I plan to make async operations as an option and default to on. If users can't accept high version, they can just use c++11 with our sync API.
About rust side,
cxx
's native async support is still on the way. It plans to supportstd
. Currently, it recommends to use synchronouschannel
to expose async operation.