Made max stamp workers and worker niceness configurable

This commit is contained in:
Mark Qvist 2026-11-10 10:49:44 +01:00
parent 132ec70f75
commit 16621a78e3
No known key found for this signature in database
2 changed files with 20 additions and 0 deletions

View file

@ -550,6 +550,14 @@ class Reticulum:
v = self.config["stamps"].as_float(option)
RNS.Transport.PR_STAMP_TIMEOUT = max(0.020, v)
if option == "max_workers":
v = self.config["stamps"].as_int(option)
RNS.Stamps.MAX_WORKERS = max(1, v)
if option == "worker_niceness":
v = self.config["stamps"].as_int(option)
RNS.Stamps.NICENESS = min(20, max(0, v))
if "reticulum" in self.config:
for option in self.config["reticulum"]:
value = self.config["reticulum"][option]

View file

@ -49,6 +49,8 @@ RSTATE_MULTIPLIER = 2
STAMP_SIZE = 32
PN_VALIDATION_POOL_MIN_SIZE = 256
USE_WORKER_MANAGER = False
MAX_WORKERS = None
NICENESS = 16
POOLING_THRESHOLD_COST = 14
KEYSTAMP_POOLING_THRESHOLD = 10
STOP_CHECK_INTERVAL = 64
@ -492,6 +494,7 @@ def job_linux_managed(stamp_cost, workblock, message_id, size, mode=MODE_STAMP):
ctx = multiprocessing.get_context("fork")
cores = multiprocessing.cpu_count()
jobs = cores if cores <= 12 else int(cores/2)
if MAX_WORKERS and jobs > MAX_WORKERS: jobs = MAX_WORKERS
allow_kill = True
stamp = None
@ -501,6 +504,9 @@ def job_linux_managed(stamp_cost, workblock, message_id, size, mode=MODE_STAMP):
RNS.log(f"Starting {jobs} stamp generation workers", RNS.LOG_DEBUG)
def job(stop_event, sc, wb, pn, mode):
try: os.nice(NICENESS)
except: pass
target = target_from_fp(sc)
if mode == MODE_STAMP: result, rounds, _ = _loop_hash(wb, target, size, stop_event.is_set)
@ -572,8 +578,12 @@ def job_linux(stamp_cost, workblock, message_id, size, mode=MODE_STAMP):
stop_event = multiprocessing.Event()
result_queue = multiprocessing.Queue(1)
rounds_queue = multiprocessing.Queue()
if MAX_WORKERS and jobs > MAX_WORKERS: jobs = MAX_WORKERS
def job(stop_event, pn, sc, wb, mode):
try: os.nice(NICENESS)
except: pass
target = target_from_fp(sc)
if mode == MODE_STAMP: result, rounds, _ = _loop_hash(wb, target, size, stop_event.is_set)
@ -749,6 +759,8 @@ def job_android_persistent(stamp_cost, workblock, message_id, size, mode=MODE_ST
try: jobs = len(os.sched_getaffinity(0))
except Exception: jobs = multiprocessing.cpu_count()
if MAX_WORKERS and jobs > MAX_WORKERS: jobs = MAX_WORKERS
no_pool = False
if len(workblock) <= WORKBLOCK_EXPAND_CHUNK*ANDROID_NO_POOL_WB_EXPAND_MAX:
if mode == MODE_STAMP and stamp_cost < ANDROID_POOLING_THRESHOLD_COST_FP: no_pool = True