aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/config.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-11 19:09:04 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-11 19:09:04 +0200
commit176b5ed563f7022009b70751e62b7ee7901e6da0 (patch)
treedfc3d3b4653cb63ef680cfd5d914fe52ba3a9635 /packages/meshbay-node/src/meshbay_node/config.py
parentaca58f66df5c21be71a7159620d0b50bb969199f (diff)
downloadmeshbay-176b5ed563f7022009b70751e62b7ee7901e6da0.tar.gz
feat(node): carry connections on several cores
connection_processes (default 1) starts that many processes for the WebRTC stack; sessions and keys stay in the node. Set from node.toml or the Node page, applied to new connections. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/config.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/config.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/config.py b/packages/meshbay-node/src/meshbay_node/config.py
index eb694ae..c5596f1 100644
--- a/packages/meshbay-node/src/meshbay_node/config.py
+++ b/packages/meshbay-node/src/meshbay_node/config.py
@@ -74,6 +74,14 @@ max_concurrent_uploads = 8
# the partial file is deleted.
max_upload_gb = 8
+# How many processes carry the connections of members. At 1 the node does it
+# all in one process, on one core: about 35 MB/s summed over every transfer in
+# progress. Above 1 the node starts that many processes for the connections and
+# keeps the rest for itself, so transfers use that many cores, plus part of one
+# for the node. Takes effect for new connections, without a restart. Not above
+# the number of cores of this machine.
+connection_processes = 1
+
# HEVC sources have no browser decoder on most platforms, so streaming one is
# transcoded to H264 rather than the usual free copy โ€” real CPU per viewer.
# Set to false only if every viewer's client is known to decode HEVC itself.
@@ -193,6 +201,9 @@ class NodeConfig:
# concurrency. There is still no aggregate quota (MESHBAY_DESIGN.md
# ยง15.3), so this is what stands between a writable root and a full disk.
max_upload_gb: float = 8.0
+ # How many processes hold the peer connections. One means this process
+ # holds them itself, as it always did. See transport/webrtc/workers.py.
+ connection_processes: int = 1
# HEVC (and any future codec in media_probe.py's
# BROWSER_INCOMPATIBLE_VIDEO_CODECS) has no decoder in most browsers, so
# streaming it needs a real re-encode to H264 rather than the usual free
@@ -289,6 +300,11 @@ class Config:
return self.groups[0] if self.groups else GroupConfig()
+def max_processes() -> int:
+ """The most connection processes this machine can use: one per core."""
+ return max(1, os.cpu_count() or 1)
+
+
def _positive(value: object, default: int, name: str) -> int:
"""A count that must be at least one, or the default with a word about it.
@@ -389,6 +405,7 @@ def node_settings_defaults(nd: NodeConfig | None = None) -> dict:
"max_concurrent_downloads": nd.max_concurrent_downloads,
"max_concurrent_uploads": nd.max_concurrent_uploads,
"max_upload_gb": nd.max_upload_gb,
+ "connection_processes": nd.connection_processes,
"transcode_incompatible_video": nd.transcode_incompatible_video,
"stun_servers": nd.stun_servers or list(DEFAULT_STUN_SERVERS),
"ice_interfaces": nd.ice_interfaces,
@@ -438,6 +455,9 @@ def load_config(path: Path = DEFAULT_CONFIG_PATH) -> Config:
cfg.node.max_upload_gb = _positive_float(
nd.get("max_upload_gb", cfg.node.max_upload_gb),
cfg.node.max_upload_gb, "max_upload_gb")
+ cfg.node.connection_processes = min(max_processes(), _positive(
+ nd.get("connection_processes", cfg.node.connection_processes),
+ cfg.node.connection_processes, "connection_processes"))
cfg.node.transcode_incompatible_video = bool(
nd.get("transcode_incompatible_video", cfg.node.transcode_incompatible_video))
cfg.node.hardware_video_encode = bool(