Skip to content

Multi threading with hyper-express #78

Answered by kartikk221
flaxeneel2 asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not sure what exact problem you are having but you can simply use the cluster module in Node.js to multi-thread HyperExpress instances to have them handle their own payloads similar to all other webservers. Below is an example code snippet to do this with some usage comments:

// NOTE: Any global code/variables will be executed for both the master and forked worker processes
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const HyperExpress = require('hyper-express');

// Check if the current process is the master process
if (cluster.isPrimary) {
   // NOTE: Code inside of this block will only run ONCE in the master/primary process

   // Spawn the init…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
4 replies
@flaxeneel2
Comment options

@kartikk221
Comment options

@flaxeneel2
Comment options

@ImLunaHey
Comment options

Answer selected by kartikk221
Comment options

You must be logged in to vote
2 replies
@electrovir
Comment options

@electrovir
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants