Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-cluster

Package Overview
Dependencies
Maintainers
5
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-cluster - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

6

History.md
1.4.0 / 2017-02-13
==================
* feat:add sticky cluster mode (#14)
* test: add test for agent debug port (#13)
1.3.0 / 2017-01-20

@@ -3,0 +9,0 @@ ==================

17

lib/app_worker.js

@@ -37,3 +37,18 @@ 'use strict';

server.listen(options.port);
if (options.sticky) {
server.listen(0, '127.0.0.1');
// Listen to messages sent from the master. Ignore everything else.
process.on('message', (message, connection) => {
if (message !== 'sticky-session:connection') {
return;
}
// Emulate a connection event on the server by emitting the
// event with the connection the master sent us.
server.emit('connection', connection);
connection.resume();
});
} else {
server.listen(options.port);
}
}

@@ -40,0 +55,0 @@

@@ -61,4 +61,5 @@ 'use strict';

this.isStarted = true;
this.logger.info('[master] %s started on %s://127.0.0.1:%s (%sms)',
frameworkPkg.name, this.options.https ? 'https' : 'http', this.options.port, Date.now() - startTime);
const stickyMsg = this.options.sticky ? ' with STICKY MODE!' : '';
this.logger.info('[master] %s started on %s://127.0.0.1:%s (%sms)%s',
frameworkPkg.name, this.options.https ? 'https' : 'http', this.options.port, Date.now() - startTime, stickyMsg);

@@ -95,2 +96,32 @@ const action = 'egg-ready';

startMasterSocketServer(cb) {
// Create the outside facing server listening on our port.
require('net').createServer({ pauseOnConnect: true }, connection => {
// We received a connection and need to pass it to the appropriate
// worker. Get the worker for this connection's source IP and pass
// it the connection.
const worker = this.stickyWorker(connection.remoteAddress);
worker.send('sticky-session:connection', connection);
}).listen(this.options.port, cb);
}
stickyWorker(ip) {
const workerNumbers = this.options.workers;
const ws = Array.from(this.workers.keys());
const wsd = ws.map(w => w % workerNumbers);
let s = '';
for (let i = 0; i < ip.length; i++) {
if (!isNaN(ip[i])) {
s += ip[i];
}
}
s = Number(s);
const idx = wsd.indexOf(s % workerNumbers);
const pid = ws[idx];
return this.workers.get(pid);
}
forkAgentWorker() {

@@ -296,3 +327,3 @@ this.agentStartTime = Date.now();

// ignore unspecified port
if (String(address.port) !== String(this.options.port)) {
if (!this.options.sticky && (String(address.port) !== String(this.options.port))) {
return;

@@ -315,3 +346,11 @@ }

this.isAllAppWorkerStarted = true;
this.ready(true);
if (this.options.sticky) {
this.startMasterSocketServer(err => {
if (err) return this.ready(err);
this.ready(true);
});
} else {
this.ready(true);
}
}

@@ -318,0 +357,0 @@

14

package.json
{
"name": "egg-cluster",
"version": "1.3.0",
"version": "1.4.0",
"description": "cluster manager for egg",

@@ -36,3 +36,3 @@ "main": "index.js",

"cluster-reload": "^1.0.2",
"debug": "^2.4.5",
"debug": "^2.6.0",
"detect-port": "^1.1.0",

@@ -47,6 +47,6 @@ "egg-logger": "^1.5.0",

"egg": "*",
"egg-bin": "^1.9.1",
"egg-bin": "^2.0.1",
"egg-ci": "^1.0.2",
"egg-mock": "^1.2.0",
"eslint": "^3.12.2",
"egg-mock": "^2.1.0",
"eslint": "^3.14.0",
"eslint-config-egg": "^3.2.0",

@@ -58,7 +58,7 @@ "pedding": "^1.1.0",

"engines": {
"node": ">= 4.4.7"
"node": ">= 6.0.0"
},
"ci": {
"version": "4, 6"
"version": "6, 7"
}
}

@@ -59,2 +59,3 @@ # egg-cluster

| workers | `Number` | numbers of app workers |
| sticky | `Boolean` | sticky mode server |
| port | `Number` | port |

@@ -61,0 +62,0 @@ | https | `Boolean` | start a https server |

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc