mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +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`);
|
||||
const init = services[name as keyof typeof services];
|
||||
await init(app, server as https.Server, env.SERVICES);
|
||||
const { default: init } = await services[name as keyof typeof services]();
|
||||
await Promise.resolve(init(app, server as https.Server, env.SERVICES));
|
||||
}
|
||||
|
||||
server.on("error", (err) => {
|
||||
@@ -258,8 +258,11 @@ const isWebProcess =
|
||||
env.SERVICES.includes("api") ||
|
||||
env.SERVICES.includes("collaboration");
|
||||
|
||||
const isWorkerProcess =
|
||||
env.SERVICES.length === 1 && env.SERVICES.includes("worker");
|
||||
|
||||
void throng({
|
||||
master,
|
||||
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";
|
||||
import cron from "./cron";
|
||||
import web from "./web";
|
||||
import websockets from "./websockets";
|
||||
import worker from "./worker";
|
||||
|
||||
export default {
|
||||
websockets,
|
||||
collaboration,
|
||||
admin,
|
||||
web,
|
||||
worker,
|
||||
cron,
|
||||
/**
|
||||
* Services are lazily imported so that only the modules for the services
|
||||
* actually being run are loaded into memory. For example, a worker-only
|
||||
* process does not need to import the web or collaboration services and their
|
||||
* (often heavy) dependency trees.
|
||||
*/
|
||||
const services = {
|
||||
websockets: () => import("./websockets"),
|
||||
collaboration: () => import("./collaboration"),
|
||||
admin: () => import("./admin"),
|
||||
web: () => import("./web"),
|
||||
worker: () => import("./worker"),
|
||||
cron: () => import("./cron"),
|
||||
} as const;
|
||||
|
||||
export default services;
|
||||
|
||||
Reference in New Issue
Block a user