diff --git a/src/server/test/test_helpers.ts b/src/server/test/test_helpers.ts index 85bae06485..b9af378375 100644 --- a/src/server/test/test_helpers.ts +++ b/src/server/test/test_helpers.ts @@ -152,6 +152,7 @@ export async function newTestDB(): Promise { export async function newTestWebserverConfig(): Promise { return { assetServerMode: "local", + assetServerWorkersPerCpu: 1, bikkieCacheMode: "none", biscuitMode: "memory", chatApiMode: "shim", diff --git a/src/server/web/config.ts b/src/server/web/config.ts index d41f6a3e98..2777844513 100644 --- a/src/server/web/config.ts +++ b/src/server/web/config.ts @@ -6,6 +6,7 @@ export type AssetServerMode = "none" | "lazy" | "local" | "proxy"; export interface WebServerConfig extends BaseServerConfig { assetServerMode: AssetServerMode; + assetServerWorkersPerCpu: number; } export async function registerWebServerConfig(): Promise { @@ -16,5 +17,10 @@ export async function registerWebServerConfig(): Promise { defaultValue: process.env.NODE_ENV === "production" ? "none" : "proxy", alias: "a", }, + assetServerWorkersPerCpu: { + type: Number, + defaultValue: 4, + alias: "w", + }, }); } diff --git a/src/server/web/main.ts b/src/server/web/main.ts index bb9aba6dae..51c06ae2c8 100644 --- a/src/server/web/main.ts +++ b/src/server/web/main.ts @@ -39,10 +39,11 @@ async function registerAssetServer( const createAssetServer = async () => { // In production we're running the asset server as its own service // so we want to use all the CPUs available to it. - const workerPoolSize = + const availableCpus = process.env.NODE_ENV === "production" ? numCpus() : Math.max(1, numCpus() - 1); + const workerPoolSize = availableCpus * config.assetServerWorkersPerCpu; log.info(`Initializing asset server with ${workerPoolSize} workers.`); const bakery = await loader.get("bakery"); return new AssetExportsServerImpl(bakery.binaries, workerPoolSize);