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

Increase asset server worker pool #32

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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
Loading