mimosa icon indicating copy to clipboard operation
mimosa copied to clipboard

Cluster-Support

Open Anachron opened this issue 9 years ago • 6 comments

I would like to create something like this: https://github.com/rowanmanning/learning-express-cluster/blob/master/app.js

// Include the cluster module
var cluster = require('cluster');

// Code to run if we're in the master process
if (cluster.isMaster) {

    // Count the machine's CPUs
    var cpuCount = require('os').cpus().length;

    // Create a worker for each CPU
    for (var i = 0; i < cpuCount; i += 1) {
        cluster.fork();
    }

    // Listen for dying workers
    cluster.on('exit', function (worker) {

        // Replace the dead worker, we're not sentimental
        console.log('Worker ' + worker.id + ' died :(');
        cluster.fork();

    });

// Code to run if we're in a worker process
} else {

    // Include Express
    var express = require('express');

    // Create a new Express application
    var app = express();

    // Add a basic route – index page
    app.get('/', function (req, res) {
        res.send('Hello from Worker ' + cluster.worker.id);
    });

    // Bind to a port
    app.listen(3000);
    console.log('Worker ' + cluster.worker.id + ' running!');

}

But sadly mimosa can only handle one server instance. Is it possible to accept multiple servers for the callback?

Edit: I know this is possible by using a custom server, however, I do not want to use all the server-reload and such functionality that come by mimosa modules.

Anachron avatar Oct 19 '14 15:10 Anachron

You do NOT want to use server reload?

If you don't want to use server/live-reload, then there's no need to bother handing your server back.

dbashford avatar Oct 21 '14 01:10 dbashford

Woops, I mean I do want to use it. Typo :)

Anachron avatar Oct 21 '14 04:10 Anachron

Ping @dbashford :)

Anachron avatar Oct 23 '14 14:10 Anachron

Pong!

Not going to happen in short order I'm afraid. I'm not going to edit mimosa-server or mimosa-server-reload, which I assume are the important ones. I'd rather create a mimosa-server-cluster that focuses on that issue. Ditto mimosa-server-cluster-reload. Welcome to give that a shot.

dbashford avatar Oct 23 '14 18:10 dbashford

You don't like me :cry: Well I'm surely giving mimosa-server-cluster a shot. Hope it is easy to implement since mimosa is so flexible :+1:

Anachron avatar Oct 23 '14 20:10 Anachron

Take mimosa-server, remove all the defaultServer stuff (the inside-mimosa hosting), leave the rest, but expect an array back. =)

dbashford avatar Oct 23 '14 20:10 dbashford