-
Notifications
You must be signed in to change notification settings - Fork 5
[src && example] Fix client lifecycle, buffer handling, and demo init #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1647c86
ea2f643
b08baff
d23150a
24083a4
46eddb0
51662d1
4aedc0e
9899480
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,7 +23,67 @@ cmake --build build_release -j | |||||||||||||
| Notes: | ||||||||||||||
| - Requires a C++17 compiler, CMake, and liburing. | ||||||||||||||
| - RPC demo uses protobuf. | ||||||||||||||
| - You can tune io_uring entries with `TAOTU_IORING_ENTRIES` if memory is tight. | ||||||||||||||
|
|
||||||||||||||
| ## Configuration | ||||||||||||||
|
|
||||||||||||||
| ### CMake options | ||||||||||||||
|
|
||||||||||||||
| You can configure build behavior with: | ||||||||||||||
|
|
||||||||||||||
| - `-DCMAKE_BUILD_TYPE=Release|Debug` (or other CMake build types) | ||||||||||||||
| - `-DTAOTU_ENABLE_CLANG_TIDY=ON|OFF` (default `OFF`) | ||||||||||||||
| - `-DTAOTU_ENABLE_CLANG_FORMAT=ON|OFF` (default `OFF`) | ||||||||||||||
|
|
||||||||||||||
| ### Runtime environment variables (core io_uring backend) | ||||||||||||||
|
|
||||||||||||||
| These are read at process startup by `Poller`: | ||||||||||||||
|
|
||||||||||||||
| - `TAOTU_ENABLE_BUF_RING` | ||||||||||||||
| - Default: enabled (best effort) | ||||||||||||||
| - Effect: enable io_uring buffer ring (`buf_ring`) for provided buffers | ||||||||||||||
| (values non-empty and not `'0'` enable). When enabled and supported by the | ||||||||||||||
| running kernel/liburing, returning a recv-multishot provided buffer becomes | ||||||||||||||
| a user-space operation (no extra `IORING_OP_PROVIDE_BUFFERS` SQE). | ||||||||||||||
| - `TAOTU_DISABLE_BUF_RING` | ||||||||||||||
| - Default: disabled | ||||||||||||||
| - Effect: force-disable `buf_ring` provided-buffer path and fallback to the | ||||||||||||||
| legacy `IORING_OP_PROVIDE_BUFFERS` path (`non-empty` and not `'0'` disables), | ||||||||||||||
| takes precedence over `TAOTU_ENABLE_BUF_RING`. | ||||||||||||||
| - `TAOTU_IORING_ENTRIES` | ||||||||||||||
| - Default: `32768` | ||||||||||||||
| - Clamp range: `[1024, 32768]` | ||||||||||||||
| - Effect: io_uring queue depth (can reduce memory footprint when lowered). | ||||||||||||||
| - `TAOTU_ENABLE_SQPOLL` | ||||||||||||||
| - Default: disabled | ||||||||||||||
| - Effect: request io_uring SQPOLL mode (`non-empty` and not `'0'` enables). | ||||||||||||||
| - `TAOTU_DISABLE_SQPOLL` | ||||||||||||||
| - Default: disabled | ||||||||||||||
| - Effect: force-disable SQPOLL (`non-empty` and not `'0'` disables), takes precedence over `TAOTU_ENABLE_SQPOLL`. | ||||||||||||||
| - `TAOTU_DISABLE_RECV_MULTISHOT` | ||||||||||||||
| - Default: disabled | ||||||||||||||
| - Effect: disable recv-multishot + provided-buffer registration path. | ||||||||||||||
| - `TAOTU_IORING_SUBMIT_BATCH` | ||||||||||||||
| - Default: `16` | ||||||||||||||
| - Max clamp: `256` | ||||||||||||||
| - Effect: submit SQEs when pending count reaches this threshold (or when forced by the loop). | ||||||||||||||
| - `TAOTU_IORING_OP_POOL_LIMIT` | ||||||||||||||
| - Default: `65536` | ||||||||||||||
| - Max clamp: `1048576` | ||||||||||||||
| - Effect: max cached io_uring operation objects per `Poller` for allocation reuse. | ||||||||||||||
| - `TAOTU_IORING_BORROWED_BUFFER_LIMIT` | ||||||||||||||
| - Default: `kBufCount/2` (currently `128`) | ||||||||||||||
| - Clamp range: `[0, kBufCount]` | ||||||||||||||
| - Effect: max number of recv-multishot provided buffers that can be leased | ||||||||||||||
| (held past the read CQE) for the borrowed-send fast path; `0` disables | ||||||||||||||
| leasing (borrowed send falls back to copy). | ||||||||||||||
|
Comment on lines
+73
to
+78
|
||||||||||||||
| - `TAOTU_IORING_BORROWED_BUFFER_LIMIT` | |
| - Default: `kBufCount/2` (currently `128`) | |
| - Clamp range: `[0, kBufCount]` | |
| - Effect: max number of recv-multishot provided buffers that can be leased | |
| (held past the read CQE) for the borrowed-send fast path; `0` disables | |
| leasing (borrowed send falls back to copy). |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,7 +23,65 @@ cmake --build build_release -j | |||||||||||||
| 说明: | ||||||||||||||
| - 需要 C++17 编译器、CMake 和 liburing。 | ||||||||||||||
| - RPC 示例需要 protobuf。 | ||||||||||||||
| - 如果内存吃紧,可以通过 `TAOTU_IORING_ENTRIES` 调小 io_uring 队列大小。 | ||||||||||||||
|
|
||||||||||||||
| ## 配置项 | ||||||||||||||
|
|
||||||||||||||
| ### CMake 选项 | ||||||||||||||
|
|
||||||||||||||
| 可通过以下参数配置构建行为: | ||||||||||||||
|
|
||||||||||||||
| - `-DCMAKE_BUILD_TYPE=Release|Debug`(或其他 CMake 构建类型) | ||||||||||||||
| - `-DTAOTU_ENABLE_CLANG_TIDY=ON|OFF`(默认 `OFF`) | ||||||||||||||
| - `-DTAOTU_ENABLE_CLANG_FORMAT=ON|OFF`(默认 `OFF`) | ||||||||||||||
|
|
||||||||||||||
| ### 运行时环境变量(核心 io_uring 后端) | ||||||||||||||
|
|
||||||||||||||
| 以下变量会在进程启动时由 `Poller` 读取: | ||||||||||||||
|
|
||||||||||||||
| - `TAOTU_ENABLE_BUF_RING` | ||||||||||||||
| - 默认:开启(尽力启用) | ||||||||||||||
| - 作用:启用 io_uring 的 buffer ring(`buf_ring`)作为 provided-buffer 的回收机制 | ||||||||||||||
| (值非空且不为 `'0'` 时启用)。当开启且系统内核/liburing 支持时,recv-multishot | ||||||||||||||
| 的 buffer 归还会变成纯用户态操作(不再需要额外提交 `IORING_OP_PROVIDE_BUFFERS` SQE)。 | ||||||||||||||
| - `TAOTU_DISABLE_BUF_RING` | ||||||||||||||
| - 默认:关闭 | ||||||||||||||
| - 作用:强制关闭 `buf_ring` 的 provided-buffer 路径,回退到旧的 | ||||||||||||||
| `IORING_OP_PROVIDE_BUFFERS` 机制(值非空且不为 `'0'` 时禁用),优先级高于 `TAOTU_ENABLE_BUF_RING`。 | ||||||||||||||
| - `TAOTU_IORING_ENTRIES` | ||||||||||||||
| - 默认值:`32768` | ||||||||||||||
| - 限制范围:`[1024, 32768]` | ||||||||||||||
| - 作用:设置 io_uring 队列深度(调小可降低内存占用)。 | ||||||||||||||
| - `TAOTU_ENABLE_SQPOLL` | ||||||||||||||
| - 默认:关闭 | ||||||||||||||
| - 作用:请求启用 io_uring 的 SQPOLL 模式(值非空且不为 `'0'` 时启用)。 | ||||||||||||||
| - `TAOTU_DISABLE_SQPOLL` | ||||||||||||||
| - 默认:关闭 | ||||||||||||||
| - 作用:强制关闭 SQPOLL(值非空且不为 `'0'` 时关闭),优先级高于 `TAOTU_ENABLE_SQPOLL`。 | ||||||||||||||
| - `TAOTU_DISABLE_RECV_MULTISHOT` | ||||||||||||||
| - 默认:关闭 | ||||||||||||||
| - 作用:关闭 recv-multishot + provided-buffer 注册路径。 | ||||||||||||||
| - `TAOTU_IORING_SUBMIT_BATCH` | ||||||||||||||
| - 默认值:`16` | ||||||||||||||
| - 最大限制:`256` | ||||||||||||||
| - 作用:当待提交 SQE 数达到该阈值时触发提交(事件循环中也可能被强制提交)。 | ||||||||||||||
| - `TAOTU_IORING_OP_POOL_LIMIT` | ||||||||||||||
| - 默认值:`65536` | ||||||||||||||
| - 最大限制:`1048576` | ||||||||||||||
| - 作用:每个 `Poller` 可缓存复用的 io_uring 操作对象上限。 | ||||||||||||||
| - `TAOTU_IORING_BORROWED_BUFFER_LIMIT` | ||||||||||||||
| - 默认值:`kBufCount/2`(当前为 `128`) | ||||||||||||||
| - 限制范围:`[0, kBufCount]` | ||||||||||||||
| - 作用:recv-multishot 的 provided-buffer 最多允许被“借用/持有”的数量上限 | ||||||||||||||
| (读取 CQE 回调结束后暂不归还,用于借用直发);设为 `0` 可禁用借用 | ||||||||||||||
| (借用发送会自动回退为拷贝发送)。 | ||||||||||||||
|
Comment on lines
+71
to
+76
|
||||||||||||||
| - `TAOTU_IORING_BORROWED_BUFFER_LIMIT` | |
| - 默认值:`kBufCount/2`(当前为 `128`) | |
| - 限制范围:`[0, kBufCount]` | |
| - 作用:recv-multishot 的 provided-buffer 最多允许被“借用/持有”的数量上限 | |
| (读取 CQE 回调结束后暂不归还,用于借用直发);设为 `0` 可禁用借用 | |
| (借用发送会自动回退为拷贝发送)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-march=nativeand-fltoin the default Release flags can make produced binaries non-portable across CPUs and may break some toolchains/cross-compiles. Consider gating these behind an explicit CMake option (e.g.TAOTU_ENABLE_LTO/TAOTU_ENABLE_NATIVE_ARCH) rather than enabling unconditionally for all Release builds.