File tree Expand file tree Collapse file tree
packages/docusaurus/src/ssg Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,3 +27,14 @@ export const SSGWorkerThreadTaskSize: number = process.env
2727 . DOCUSAURUS_SSG_WORKER_THREAD_TASK_SIZE
2828 ? parseInt ( process . env . DOCUSAURUS_SSG_WORKER_THREAD_TASK_SIZE , 10 )
2929 : 10 ; // TODO need fine-tuning
30+
31+ // Controls worker thread recycling behavior (maxMemoryLimitBeforeRecycle)
32+ // See https://github.com/facebook/docusaurus/pull/11166
33+ // See https://github.com/facebook/docusaurus/issues/11161
34+ export const SSGWorkerThreadRecyclerMaxMemory : number | undefined = process . env
35+ . DOCUSAURUS_SSG_WORKER_THREAD_RECYCLER_MAX_MEMORY
36+ ? parseInt ( process . env . DOCUSAURUS_SSG_WORKER_THREAD_RECYCLER_MAX_MEMORY , 10 )
37+ : // TODO we should probably provide a default value here
38+ // 2gb is a quite reasonable max that should work well even for large sites
39+ // we'd rather ask community feedback first
40+ undefined ;
Original file line number Diff line number Diff line change @@ -12,7 +12,11 @@ import _ from 'lodash';
1212import logger , { PerfLogger } from '@docusaurus/logger' ;
1313import { createSSGParams } from './ssgParams' ;
1414import { renderHashRouterTemplate } from './ssgTemplate' ;
15- import { SSGWorkerThreadCount , SSGWorkerThreadTaskSize } from './ssgEnv' ;
15+ import {
16+ SSGWorkerThreadCount ,
17+ SSGWorkerThreadRecyclerMaxMemory ,
18+ SSGWorkerThreadTaskSize ,
19+ } from './ssgEnv' ;
1620import { generateHashRouterEntrypoint } from './ssgUtils' ;
1721import { createGlobalSSGResult } from './ssgGlobalResult' ;
1822import { executeSSGInlineTask } from './ssgWorkerInline' ;
@@ -124,6 +128,16 @@ const createPooledSSGExecutor: CreateSSGExecutor = async ({
124128 runtime : 'worker_threads' ,
125129 isolateWorkers : false ,
126130 workerData : { params} ,
131+
132+ // WORKER MEMORY MANAGEMENT
133+ // Allows containing SSG memory leaks with a thread recycling workaround
134+ // See https://github.com/facebook/docusaurus/pull/11166
135+ // See https://github.com/facebook/docusaurus/issues/11161
136+ maxMemoryLimitBeforeRecycle : SSGWorkerThreadRecyclerMaxMemory ,
137+ resourceLimits : {
138+ // For some reason I can't figure out how to limit memory on a worker
139+ // See https://x.com/sebastienlorber/status/1920781195618513143
140+ } ,
127141 } ) ;
128142 } ,
129143 ) ;
You can’t perform that action at this time.
0 commit comments