Permalink
Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (54 sloc) 1.58 KB

Mixture - Heterogeneous cluster task manager

Install

npm install mixture

Cluster more.

var mix = require('mixture').mix()

var ioPort = 8880
  , nodeId = 0

// announce data server
mix.task('announce').fork('data.js');

// socket.io instances
var socketio = mix.task('socket.io', { filename: 'app.js' })

for (var i = 0; i < count; i++) {
  ioPort++;
  nodeId++;

  var worker = socketio.fork({ args: [ioPort, nodeId] })
}

API

Mix Master

require mixture, create a mix

var mix = require('mixture').mix()

optionally, name your mix (for network identification)

var mixture = require('mixture')
  , mix = mixture.mix('jupiter')

Tasks

define a simple task with straightforward fork semantics.

mix.task('express').fork('server.js')
console.log(mix.name, mix.workers.length)

task returns a reference to the task that you can refer to at any point task fork accepts an options argument so you can pass in args or options for a spefic forked worker instance.

// spin up a second instance
var task = mix.task('express')
task.fork({ args: [9001] })
console.log(task.name, task.workers.length)

when you don't need a task worker anymore, just kill it

var worker = mix.task('express').workers.pop()
worker.kill()

Sample Apps

License

  • MIT