Unverified Commit 917b9aef authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Move build workers count change behind flag (#49937)

It seems the build workers count calc change that was made in https://github.com/vercel/next.js/pull/47823 caused a regression in performance as we aren't utilizing as many workers as we previously did so this moves that change behind an experimental flag while additional tweaking is investigated. 

x-ref: https://github.com/vercel/next.js/pull/47823
Fixes: https://github.com/vercel/next.js/issues/49593
parent 91861210
...@@ -1142,22 +1142,18 @@ export default async function build( ...@@ -1142,22 +1142,18 @@ export default async function build(
process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD
// We limit the number of workers used based on the number of CPUs and const numWorkers = config.experimental.memoryBasedWorkersCount
// the current available memory. This is to prevent the system from ? Math.max(
// running out of memory as well as maximize speed. We assume that config.experimental.cpus !== defaultConfig.experimental!.cpus
// each worker will consume ~1GB of memory in a production build. ? (config.experimental.cpus as number)
// For example, if the system has 10 CPU cores and 8GB of remaining memory : Math.min(
// we will use 8 workers. config.experimental.cpus || 1,
const numWorkers = Math.max( Math.floor(os.freemem() / 1e9)
config.experimental.cpus !== defaultConfig.experimental!.cpus ),
? (config.experimental.cpus as number) // enforce a minimum of 4 workers
: Math.min( 4
config.experimental.cpus || 1, )
Math.floor(os.freemem() / 1e9) : config.experimental.cpus || 4
),
// enforce a minimum of 4 workers
4
)
function createStaticWorker(type: 'app' | 'pages') { function createStaticWorker(type: 'app' | 'pages') {
const numWorkersPerType = isAppDirEnabled const numWorkersPerType = isAppDirEnabled
......
...@@ -264,6 +264,9 @@ const configSchema = { ...@@ -264,6 +264,9 @@ const configSchema = {
cpus: { cpus: {
type: 'number', type: 'number',
}, },
memoryBasedWorkersCount: {
type: 'boolean',
},
craCompat: { craCompat: {
type: 'boolean', type: 'boolean',
}, },
......
...@@ -168,6 +168,7 @@ export interface ExperimentalConfig { ...@@ -168,6 +168,7 @@ export interface ExperimentalConfig {
swcMinify?: boolean swcMinify?: boolean
swcFileReading?: boolean swcFileReading?: boolean
cpus?: number cpus?: number
memoryBasedWorkersCount?: boolean
sharedPool?: boolean sharedPool?: boolean
proxyTimeout?: number proxyTimeout?: number
isrFlushToDisk?: boolean isrFlushToDisk?: boolean
...@@ -673,6 +674,7 @@ export const defaultConfig: NextConfig = { ...@@ -673,6 +674,7 @@ export const defaultConfig: NextConfig = {
(Number(process.env.CIRCLE_NODE_TOTAL) || (Number(process.env.CIRCLE_NODE_TOTAL) ||
(os.cpus() || { length: 1 }).length) - 1 (os.cpus() || { length: 1 }).length) - 1
), ),
memoryBasedWorkersCount: false,
sharedPool: true, sharedPool: true,
isrFlushToDisk: true, isrFlushToDisk: true,
workerThreads: false, workerThreads: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment