feat(core): add an opt-in shared runtime for native instances (#2757)

* feat(core): share an instance runtime with CLI worker control

Add --shared-runtime to easytier-core and reuse --multi-thread-count.
Default shared workers to available CPUs while retaining dedicated
runtime defaults. Consume shared runtime flags at process scope so
config files remain writable and keep their own thread settings.

Share executor ownership across the factory and its instances, keeping
normal instance capabilities and independent shutdown paths. Cover
worker selection, instance deletion, hot addition, and final teardown.

* docs: document shared native runtime ownership

Describe the opt-in shared executor alongside the default per-instance model, including worker selection and last-owner shutdown semantics.
This commit is contained in:
KKRainbow
2026-10-25 22:46:11 +08:00
committed by GitHub
parent 4a91eeb379
commit dccb85ab36
7 changed files with 219 additions and 30 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
//! Native ownership and continuous driving of one instance's Tokio runtime.
//! Native ownership and continuous driving of an instance or shared Tokio runtime.
use std::sync::mpsc;
@@ -22,7 +22,7 @@ impl NativeInstanceExecutor {
.spawn(move || {
let mut builder = if multi_thread {
let mut builder = Builder::new_multi_thread();
builder.worker_threads(2.max(thread_count as usize));
builder.worker_threads(1.max(thread_count as usize));
builder
} else {
Builder::new_current_thread()
@@ -67,8 +67,8 @@ mod tests {
async fn honors_runtime_flavor_and_worker_count() {
for (multi_thread, count, expected_workers) in [
(false, 8, 1),
(true, 0, 2),
(true, 1, 2),
(true, 0, 1),
(true, 1, 1),
(true, 2, 2),
(true, 4, 4),
] {