Skip to content

Commit

Permalink
feat: Allow to customize number of workers (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviortheking authored Dec 10, 2024
1 parent c52ed81 commit ebc2bb2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import jsonEndpoints from './V2/endpoints/jsonEndpoints'
import graphql from './V2/graphql'

if (cluster.isPrimary) {
console.log(`Primary ${process.pid} is running`);
console.log(`Primary ${process.pid} is running`)

const parallelism = availableParallelism()
console.log(`creating ${parallelism} workers...`)
for (let i = 0; i < parallelism; i++) {
// get maximum number of workers available for the software
let maxWorkers = availableParallelism()

// allow to override max worker count
if (process.env.MAX_WORKERS) {
maxWorkers = Math.min(parallelism, parseInt(process.env.MAX_WORKERS))
}

// create the workers
console.log(`creating ${maxWorkers} workers...`)
for (let i = 0; i < maxWorkers; i++) {
cluster.fork();
}

Expand Down

0 comments on commit ebc2bb2

Please sign in to comment.