Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

NodeJS Multi-Core Processors Example

const cluster = require('cluster')

if (cluster.isMaster) {
  // Creates the Forks
  process.title = 'my-node-app-master'
  const { length: numberOfProcs } = require('os').cpus()
  for (let i = 0; i < numberOfProcs; i++) {
    cluster.fork()
  }

  // and here you can fork again when one of the forks dies
  cluster.on('exit', (worker, code, signal) => {
    console.error(`worker ${worker.process.pid} died (${signal || code}). restarting it in a sec`)
    setTimeout(() => cluster.fork(), 1000)
  })
} else {
  // run your server
  const http = require('http')
  process.title = 'my-node-app-fork'

  http.Server((req, res) => {
    res.writeHead(200)
    res.end(`hello world from pid ${process.pid}
`)
  }).listen(8000)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js notimplemented error 
Javascript :: js Changing selected option by option id, class, or attribute 
Javascript :: prisma.db yaml 
Javascript :: verifier si chaien ade caractere apparait dans autre js 
Javascript :: react leaflet layer disable controls while on top 
Javascript :: js number power/exponetion 
Javascript :: js function call itself 
Javascript :: change placeholder color in material ui 
Javascript :: get 3 random items from array javascript 
Javascript :: firebase hosting rewrite function You need to enable JavaScript to run this app. 
Javascript :: symfony iterate over entity 
Javascript :: v-smooth-scroll 
Javascript :: rest object javascript 
Javascript :: correct code for the { "vars": "local" } 
Javascript :: add decimal places to number javascript 
Javascript :: object wrappers in javascript 
Javascript :: pass a callback funcion into an async function node js 
Javascript :: Plumasil - new item button desc text 
Javascript :: create user controller 
Javascript :: How can I force a refresh in my spa website with vuejs - laravel 
Javascript :: javascript vuelidate identical passwords only if checkbox is ticked 
Javascript :: how to change css of menu when scrolling 
Javascript :: How to call keyup function on textbox for every dynamic generated form in Angular8 
Javascript :: AngularJS slick carousel filter by attribute 
Javascript :: Difficulties handling asynchronous taks using image-picker and copying files in react-native 
Javascript :: new Date() how can i ue 
Javascript :: image react not showing 
Javascript :: Third Example of Event Delegation In JavaScript 
Javascript :: chat v2 msg and time good 
Javascript :: switching light bulbs problem javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =