Hands-On JavaScript High Performance by Justin Scherer

Hands-On JavaScript High Performance by Justin Scherer

Author:Justin Scherer [Justin Scherer]
Language: eng
Format: epub
Tags: COM060160 - COMPUTERS / Web / Web Programming, COM051260 - COMPUTERS / Programming Languages / JavaScript, COM060180 - COMPUTERS / Web / Web Services and APIs
Publisher: Packt
Published: 2020-02-28T11:17:16+00:00


import cluster from 'cluster';

import https from 'https';

import http from 'http';

import { URL } from 'url';

Next, we set up the constants that we can use across our processes:

const numWorkers = 2;

const CACHE = 0;

const SEND = 1;

const server = '127.0.0.1';

const port = 3000;

After, we add an if/else check to see whether we are the master process or whether we are a slave process. The same file is used for both types of processes, so we need a way to distinguish between the two:

if( cluster.isMaster ) {

// do master work

} else {

// handle incoming connections

}

Now, write the master code. This will go into the first block of the if/else statement. Our master node needs to spin the slave nodes up, as well as initialize our cache:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.