mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
perf: Avoid loading unused services (#12537)
* fix: Run single process when only the worker service is enabled Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * perf: Improve memory consumption through lazy service loading --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+6
-3
@@ -184,8 +184,8 @@ async function start(_id: number, disconnect: () => void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.info("lifecycle", `Starting ${name} service`);
|
Logger.info("lifecycle", `Starting ${name} service`);
|
||||||
const init = services[name as keyof typeof services];
|
const { default: init } = await services[name as keyof typeof services]();
|
||||||
await init(app, server as https.Server, env.SERVICES);
|
await Promise.resolve(init(app, server as https.Server, env.SERVICES));
|
||||||
}
|
}
|
||||||
|
|
||||||
server.on("error", (err) => {
|
server.on("error", (err) => {
|
||||||
@@ -258,8 +258,11 @@ const isWebProcess =
|
|||||||
env.SERVICES.includes("api") ||
|
env.SERVICES.includes("api") ||
|
||||||
env.SERVICES.includes("collaboration");
|
env.SERVICES.includes("collaboration");
|
||||||
|
|
||||||
|
const isWorkerProcess =
|
||||||
|
env.SERVICES.length === 1 && env.SERVICES.includes("worker");
|
||||||
|
|
||||||
void throng({
|
void throng({
|
||||||
master,
|
master,
|
||||||
worker: start,
|
worker: start,
|
||||||
count: isWebProcess ? webProcessCount : undefined,
|
count: isWorkerProcess ? 1 : isWebProcess ? webProcessCount : undefined,
|
||||||
});
|
});
|
||||||
|
|||||||
+15
-14
@@ -1,15 +1,16 @@
|
|||||||
import admin from "./admin";
|
/**
|
||||||
import collaboration from "./collaboration";
|
* Services are lazily imported so that only the modules for the services
|
||||||
import cron from "./cron";
|
* actually being run are loaded into memory. For example, a worker-only
|
||||||
import web from "./web";
|
* process does not need to import the web or collaboration services and their
|
||||||
import websockets from "./websockets";
|
* (often heavy) dependency trees.
|
||||||
import worker from "./worker";
|
*/
|
||||||
|
const services = {
|
||||||
export default {
|
websockets: () => import("./websockets"),
|
||||||
websockets,
|
collaboration: () => import("./collaboration"),
|
||||||
collaboration,
|
admin: () => import("./admin"),
|
||||||
admin,
|
web: () => import("./web"),
|
||||||
web,
|
worker: () => import("./worker"),
|
||||||
worker,
|
cron: () => import("./cron"),
|
||||||
cron,
|
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export default services;
|
||||||
|
|||||||
Reference in New Issue
Block a user