Skip to content

Commit

Permalink
Increase asset server worker pool
Browse files Browse the repository at this point in the history
  • Loading branch information
akarpenko committed Aug 17, 2023
1 parent 79e5628 commit 19b1e86
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/server/test/test_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export async function newTestDB(): Promise<BDB> {
export async function newTestWebserverConfig(): Promise<WebServerConfig> {
return {
assetServerMode: "local",
assetServerWorkersPerCpu: 1,
bikkieCacheMode: "none",
biscuitMode: "memory",
chatApiMode: "shim",
Expand Down
6 changes: 6 additions & 0 deletions src/server/web/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebServerConfig> {
Expand All @@ -16,5 +17,10 @@ export async function registerWebServerConfig(): Promise<WebServerConfig> {
defaultValue: process.env.NODE_ENV === "production" ? "none" : "proxy",
alias: "a",
},
assetServerWorkersPerCpu: {
type: Number,
defaultValue: 4,
alias: "w",
},
});
}
3 changes: 2 additions & 1 deletion src/server/web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ async function registerAssetServer<C extends WebServerContext>(
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);
Expand Down

0 comments on commit 19b1e86

Please sign in to comment.