Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix runners count and add defaults to use all cores #24

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 20 additions & 2 deletions screeps-start.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -64,6 +65,7 @@ const installPackages = () => {
{
cwd: ModsDir,
stdio: "inherit",
encoding: "utf8",
},
);
}
Expand All @@ -75,6 +77,7 @@ const installPackages = () => {
{
cwd: ModsDir,
stdio: "inherit",
encoding: "utf8",
},
);
}
Expand Down Expand Up @@ -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 || {};
Expand Down