apache / opendal

Apache OpenDAL: One Layer, All Storage.
https://opendal.apache.org
Apache License 2.0
3.47k stars 486 forks source link

research: async support for cpp binding #3156

Open silver-ymz opened 1 year ago

silver-ymz commented 1 year ago

In cpp side, I come up with following ways:

Solutions of some popular cloud sdk:

I prefer to use std, because it provides more flexibility than asio。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 support std. Currently, it recommends to use synchronous channel to expose async operation.

Xuanwo commented 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++?

jiaoew1991 commented 1 year ago

Hi @silver-ymz, this issue is a capability that we currently need. I think there are several points to consider:

  1. The implementation of runtime and thread pool needs customization capabilities. In our scenario, we have requirements for adjusting concurrency and thread priority.

  2. 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.

  3. As a library, the C++ version should not be set too high since there may not be many users using C++20 😅

kassane commented 1 year ago

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