diff options
| author | ihc童鞋@提不起劲 <[email protected]> | 2021-12-08 21:15:26 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-08 21:15:26 +0800 |
| commit | 84461fa463ba5212641e9e5fd56d21dc188ae12c (patch) | |
| tree | 479650c59cc42acaead85f96a6780cea1af11f58 /docs | |
| parent | b9d32d216d5e1705c7a3f9956ee958414675e156 (diff) | |
feat: allow user specify thread count in macro (#7)
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/en/configuration.md | 18 | ||||
| -rw-r--r-- | docs/zh/configuration.md | 18 |
2 files changed, 32 insertions, 4 deletions
diff --git a/docs/en/configuration.md b/docs/en/configuration.md index 5e4475e..2fc9d7c 100644 --- a/docs/en/configuration.md +++ b/docs/en/configuration.md @@ -9,7 +9,7 @@ author: ihciah This section describes the configurable options and some of the default behavior inside Monoio. ## Runtime Configuration -With the current version, there are 2 main configurations that you can change at runtime. +With the current version, there are 3 main configurations that you can change at runtime. 1. entries entries refers to the ring size of the io-uring, the default is `1024`, you can specify this value when creating the runtime. Note that for performance, the setting is set to 256 when it is less than 256. When your QPS is high, setting larger entries can increase the ring size and reduce the number of submits, which will significantly reduce the syscall usage, but also bring some memory usage, please set it reasonably. @@ -40,7 +40,21 @@ With the current version, there are 2 main configurations that you can change at ``` Specified via macro: ```rust - #[monoio::main(timer_enabled)] + #[monoio::main(timer_enabled = true)] + async main() { + // ... + } + ``` + +3. worker_threads + + To take full advantage of multi-core performance, you can only start multiple threads. Normally, you can do this implicitly through a macro. + + In the macro, use `worker_threads` to manually specify the number of threads (when not specified, it will run as a single thread). When specified as `n`, it will start `n-1` threads and create Runtime in each thread and execute it; after that, Runtime is also created and executed in the main thread, and the execution is completed and waiting for other threads. + + The macro function is relatively simple to implement. If you need to do some custom behaviors when creating threads, such as binding cpu, you can only create threads and Runtimes manually. + ```rust + #[monoio::main(worker_threads = 2)] async main() { // ... } diff --git a/docs/zh/configuration.md b/docs/zh/configuration.md index 17378fd..4e5aa7f 100644 --- a/docs/zh/configuration.md +++ b/docs/zh/configuration.md @@ -9,7 +9,7 @@ author: ihciah 本节将介绍 Monoio 内部的可配置选项和一些默认行为。 ## 运行时配置 -目前版本下,在运行时你可以改动的主要有 2 个配置: +目前版本下,在运行时你可以改动的主要有 3 个配置: 1. entries entries 指 io-uring 的 ring 大小,默认是 `1024`,你可以在创建 runtime 时指定该值。注意,为了保证性能,当设定小于 256 时会设置为 256。当你的 QPS 较高时,设置较大的 entries 可以增大 ring 的大小,减少 submit 次数,这样会显著降低 syscall 占用,但也会带来一定内存占用,请合理设置。 @@ -40,7 +40,21 @@ author: ihciah ``` 通过宏指定: ```rust - #[monoio::main(timer_enabled)] + #[monoio::main(timer_enabled = true)] + async main() { + // ... + } + ``` + +3. worker_threads + + 要充分利用多核心性能,只能启动多个线程。通常情况下,你可以通过宏来隐式地做这件事。 + + 在宏中,使用 `worker_threads` 可以手动指定线程数(不指定的时候会以单线程运行)。指定为 `n` 的时候会启动 `n - 1` 个线程并在每个线程创建 Runtime 并执行;之后在主线程也创建 Runtime 并执行,执行完毕等待其他线程。 + + 宏的功能实现较为简单,如果你需要在创建线程时做一些自定义行为,如绑定 cpu,你就只能手动创建线程和 Runtime 啦。 + ```rust + #[monoio::main(worker_threads = 2)] async main() { // ... } |
