From 1954702047a1023d06f1ec14b58dd8fb6c9b472a Mon Sep 17 00:00:00 2001 From: Jonas Holst Damtoft Date: Tue, 30 Jan 2024 14:06:48 +0100 Subject: [PATCH 1/4] fix runners count and add defaults to use all cores --- config.yml | 6 ------ docker-compose.yml | 3 ++- screeps-start.js | 12 ++++++++++-- 3 files changed, 12 insertions(+), 9 deletions(-) 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/docker-compose.yml b/docker-compose.yml index 06121db..3b06f69 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,8 @@ version: "3" services: screeps: platform: linux/x86_64 - image: jomik/screeps-server:edge + # image: jomik/screeps-server:edge + build: . depends_on: - mongo - redis diff --git a/screeps-start.js b/screeps-start.js index f80c01a..097ad88 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"); @@ -125,8 +126,8 @@ const writeModsConfiguration = () => { // Map from camelCase to snake_case const ServerConfigMap = { - runnersThreads: "runner_threads", - processorsCnt: "processors_cnt", + runnerCount: "runners_threads", + processorCount: "processors_cnt", storageTimeout: "storage_timeout", logConsole: "log_console", logRotateKeep: "log_rotate_keep", @@ -138,9 +139,12 @@ const start = async () => { writeModsConfiguration(); const screeps = require("@screeps/launcher"); + const cores = os.cpus().length; 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 || {}; @@ -151,6 +155,10 @@ const start = async () => { } } + console.log( + "Starting server with options:", + JSON.stringify(options, null, 2), + ); await screeps.start(options, process.stdout); }; From 53b8d4dd8042e43700aefc6f385d7e13493049a5 Mon Sep 17 00:00:00 2001 From: Jonas Holst Damtoft Date: Tue, 30 Jan 2024 14:16:31 +0100 Subject: [PATCH 2/4] fix docker compose --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3b06f69..06121db 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,7 @@ version: "3" services: screeps: platform: linux/x86_64 - # image: jomik/screeps-server:edge - build: . + image: jomik/screeps-server:edge depends_on: - mongo - redis From ffbb8e0bc4f127d93ceff6c624df0966d3db4c6b Mon Sep 17 00:00:00 2001 From: Jonas Holst Damtoft Date: Tue, 30 Jan 2024 14:17:52 +0100 Subject: [PATCH 3/4] fixup! fix runners count and add defaults to use all cores --- screeps-start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screeps-start.js b/screeps-start.js index 097ad88..f9bc4dc 100755 --- a/screeps-start.js +++ b/screeps-start.js @@ -126,7 +126,7 @@ const writeModsConfiguration = () => { // Map from camelCase to snake_case const ServerConfigMap = { - runnerCount: "runners_threads", + runnerCount: "runners_cnt", processorCount: "processors_cnt", storageTimeout: "storage_timeout", logConsole: "log_console", From 61be56cf74345b6bb57323d0bf52ad630d43f36b Mon Sep 17 00:00:00 2001 From: Jonas Holst Damtoft Date: Tue, 30 Jan 2024 14:44:01 +0100 Subject: [PATCH 4/4] use physical cores --- screeps-start.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/screeps-start.js b/screeps-start.js index f9bc4dc..21c6231 100755 --- a/screeps-start.js +++ b/screeps-start.js @@ -65,6 +65,7 @@ const installPackages = () => { { cwd: ModsDir, stdio: "inherit", + encoding: "utf8", }, ); } @@ -76,6 +77,7 @@ const installPackages = () => { { cwd: ModsDir, stdio: "inherit", + encoding: "utf8", }, ); } @@ -134,12 +136,24 @@ const ServerConfigMap = { 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 = os.cpus().length; + const cores = getPhysicalCores(); + const options = { steam_api_key: process.env.STEAM_KEY || config.steamKey, storage_disable: false, @@ -155,10 +169,6 @@ const start = async () => { } } - console.log( - "Starting server with options:", - JSON.stringify(options, null, 2), - ); await screeps.start(options, process.stdout); };