Comments (2)
Not planned yet.
The main reason is that the compiler we're using internally (GCC 8) does not support C++20 coroutine. That means we won't be able to test coroutine support throughly in production environment (were it implemented).
I have't looked deeply enough into C++20 coroutine. The following is based on my preliminary understanding.
Were it to be implemented, I'd expect operator co_await
overload for Future<T>
to be provided. This way the following should be possible:
Future<...> AsyncDoSomething() {
co_await some_client.AsyncDoSomeOtherThing();
}
However, I don't see much point in doing this, when compared with:
... DoSomething() {
some_cient.DoSomeOtherThing();
}
The reason is that, to permit concurrent packet deserialization, the framework nonetheless needs to use a dedicated fiber for each request.
Therefore we always have one dedicated stack for each request, regardless whether we're using a stackless coroutine to handle it, or handling it directly in fiber. This ruins the main point of using C++20 coroutine (allocating state on heap and avoid using a stack).
Besides, by using a dedicated stack (which is allocated quickly enough in fast path, using our object pool), we can (hopefully) allocate most states (ignoring indirect allocations done by containers) simply by adjusting the stack pointer, without incurring calls to memory allocator. This is generally a performance gain. To the contrary, C++20 coroutine would require the compiler to do one heap allocation for each call to coroutine (unless the compiler is able to optimize that away, in certain cases).
That said, I do see a point in supporting waiting for coroutine result in fiber though, such as:
flare::fiber::WaitOnAwaitable(some_cpp20_async_read_function());
This would allow us to interoperate with libraries using C++20 coroutine, once they're widely spreaded.
I'd expect this to be done once we upgraded our compiler to a more recent one. This should be trivially implementable using an approach similar to cppcoro::sync_wait
(using fiber-friendly synchronization primitives).
(Here I'm assuming the coroutine does "return" only once. For generator-alike coroutines, as far as I understand
it, it's need no support from the underlying framework.)
from flare.
Thanks for your detailed reply. I will read the code to get a deeper understanding.
from flare.
Related Issues (20)
- Http header data structure HOT 13
- Rpc: Http parse HOT 5
- 针对K8s容器环境是否有需要注意的优化配置呢 HOT 2
- clang-format HOT 15
- update blade HOT 9
- logging HOT 11
- if have any plan to support bazel HOT 1
- bazel build ... 失败 HOT 6
- 请问有合适的源码阅读顺序吗 HOT 5
- 对GetFreeCount的取值比较困惑 HOT 5
- Does the server example in the flare example support 1 thread start? HOT 4
- clang-17 asan/tsan fiber coredump
- 关于Function类的疑问 HOT 2
- 问一个非常诡异的用例 HOT 10
- 关于调度参数的疑问 HOT 1
- 编译时间太长 HOT 4
- 调试相关 HOT 3
- Fiber scheduling takes too long HOT 3
- Can it support machines with large cores HOT 4
- 使用`getaddrinfo`会不会更好一点 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flare.