@@ -91,25 +91,23 @@ async function setupWorker (id, disconnect) {
9191}
9292
9393function calculateWorkerCount ( ) {
94- // Heroku's recommended WEB_CONCURRENCY count based on the WEB_MEMORY config
94+ // Heroku's recommended WEB_CONCURRENCY count based on the WEB_MEMORY config,
95+ // or explicitly configured by us
9596 const { WEB_CONCURRENCY } = process . env
9697
97- const recommendedCount = parseInt ( WEB_CONCURRENCY , 10 ) || 1
98+ const recommendedCount = parseInt ( WEB_CONCURRENCY , 10 )
9899 const cpuCount = os . cpus ( ) . length
99100
100101 // Ensure the recommended count is AT LEAST 1 for safety
101- let workerCount = Math . max ( recommendedCount , 1 )
102-
103- // Let's do some math...
104- // If in a deployed environment...
105- if ( NODE_ENV === 'production' ) {
106- // If WEB_MEMORY or WEB_CONCURRENCY values were configured in Heroku, use
107- // the smaller value between their recommendation vs. the CPU count
108- if ( WEB_CONCURRENCY ) {
109- workerCount = Math . min ( recommendedCount , cpuCount )
110- } else {
111- workerCount = cpuCount
112- }
102+ let workerCount = Math . max ( recommendedCount || 1 , 1 )
103+
104+ // If WEB_CONCURRENCY value was configured to a valid number...
105+ if ( recommendedCount > 0 ) {
106+ // Use the smaller value between the recommendation vs. the CPU count
107+ workerCount = Math . min ( workerCount , cpuCount )
108+ } else if ( NODE_ENV === 'production' ) {
109+ // Else if in a deployed environment, default to the CPU count
110+ workerCount = cpuCount
113111 }
114112
115113 return workerCount
0 commit comments