diff --git a/config.yml b/config.yml index 793ae80..9d3d967 100644 --- a/config.yml +++ b/config.yml @@ -6,11 +6,5 @@ bots: simplebot: screepsbot-zeswarm serverOptions: - # The number of parallel runner threads in which player scripts are executed. - # Don't set this option greater than the number of your physical CPU cores. - runnerThreads: 4 - # The number of room processor worker processes to launch. - # Don't set this option greater than the number of your physical CPU cores. - processorsCnt: 2 # If set, forward console messages to terminal logConsole: false diff --git a/screeps-start.js b/screeps-start.js index f80c01a..21c6231 100755 --- a/screeps-start.js +++ b/screeps-start.js @@ -1,5 +1,6 @@ #! /usr/bin/env node const fs = require("fs"); +const os = require("os"); const path = require("path"); const yaml = require("js-yaml"); const { execSync } = require("child_process"); @@ -64,6 +65,7 @@ const installPackages = () => { { cwd: ModsDir, stdio: "inherit", + encoding: "utf8", }, ); } @@ -75,6 +77,7 @@ const installPackages = () => { { cwd: ModsDir, stdio: "inherit", + encoding: "utf8", }, ); } @@ -125,22 +128,37 @@ const writeModsConfiguration = () => { // Map from camelCase to snake_case const ServerConfigMap = { - runnersThreads: "runner_threads", - processorsCnt: "processors_cnt", + runnerCount: "runners_cnt", + processorCount: "processors_cnt", storageTimeout: "storage_timeout", logConsole: "log_console", logRotateKeep: "log_rotate_keep", restartInterval: "restart_interval", }; +const getPhysicalCores = () => { + const nproc = execSync("nproc --all", { encoding: "utf8" }); + + const cores = Number.parseInt(nproc.trim(), 10); + if (Number.isNaN(cores) && cores < 1) { + console.warn("Error getting number of physical cores, defaulting to 1"); + return 1; + } + return cores; +}; + const start = async () => { installPackages(); writeModsConfiguration(); const screeps = require("@screeps/launcher"); + const cores = getPhysicalCores(); + const options = { steam_api_key: process.env.STEAM_KEY || config.steamKey, storage_disable: false, + processors_cnt: cores, + runners_cnt: Math.max(cores - 1, 1), }; const serverOptions = config.serverOptions || {};