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
+12 -7
View File
@@ -364,13 +364,18 @@ A core instance:
`CoreProcessRuntime`, plus optional protocol and platform capabilities. The
bundle carries capabilities, not preconstructed portable managers.
The standard native factory owns one continuously driven Tokio executor per
instance. `multi_thread` selects a multi-thread or current-thread runtime;
`multi_thread_count` sets the worker count with the historical minimum of two.
Construction, start/stop, and FFI data-plane tasks use that executor, independent
of the process management runtime. Dropping its Host owner shuts down the
executor without blocking a worker on its own termination. Compact and WASI
Hosts retain their externally supplied execution model.
By default, the standard native factory owns one continuously driven Tokio
executor per instance. `multi_thread` selects a multi-thread or current-thread
runtime; `multi_thread_count` sets the worker count with the historical minimum
of two. The `easytier-core --shared-runtime` option instead shares one
multi-thread executor across the factory and all its instances. Its worker count
defaults to the available CPU count and can be set with the process-level
`--multi-thread-count` option, with a minimum of one; per-instance runtime flags
are ignored in this mode. Construction, start/stop, and FFI data-plane tasks use
the selected executor, independent of the process management runtime. Dropping
the last factory or instance Host owner shuts down the executor without blocking
a worker on its own termination. Compact and WASI Hosts retain their externally
supplied execution model.
Each Module owns partial-start cleanup for its internal resources.
`CoreInstance` has one outer cancellation and recovery path for the complete