Skip to content

Commit

Permalink
feat: cluster-client support single cpu mode (#3497)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxcsoccer authored and dead-horse committed Feb 26, 2019
1 parent f7e6ab5 commit db10931
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class EggApplication extends EggCore {
*/
this.cluster = (clientClass, options) => {
options = Object.assign({}, this.config.clusterClient, options, {
singleMode: this.options.mode === 'single',
// cluster need a port that can't conflict on the environment
port: this.options.clusterPort,
// agent worker is leader, app workers are follower
Expand Down
3 changes: 0 additions & 3 deletions lib/start.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
'use strict';

const detectPort = require('detect-port');
const path = require('path');

module.exports = async (options = {}) => {
console.warn('single process mode is still in experiment, please don\'t use it in production environment');

options.baseDir = options.baseDir || process.cwd();
options.mode = 'single';
// FIXME: cluster-client support single process mode
options.clusterPort = await detectPort();

// get agent from options.framework and package.egg.framework
if (!options.framework) {
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
"dependencies": {
"@types/accepts": "^1.3.5",
"@types/koa": "^2.0.48",
"@types/koa-router": "^7.0.39",
"@types/koa-router": "^7.0.40",
"@types/urllib": "^2.28.1",
"accepts": "^1.3.5",
"agentkeepalive": "^4.0.0",
"agentkeepalive": "^4.0.2",
"cache-content-type": "^1.0.1",
"circular-json-for-egg": "^1.0.0",
"cluster-client": "^2.1.2",
"cluster-client": "^3.0.0",
"debug": "^4.1.1",
"delegates": "^1.0.0",
"detect-port": "^1.3.0",
"egg-cluster": "^1.22.2",
"egg-cookies": "^2.2.6",
"egg-core": "^4.14.0",
"egg-core": "^4.14.1",
"egg-development": "^2.4.2",
"egg-i18n": "^2.0.0",
"egg-jsonp": "^2.0.0",
Expand All @@ -36,9 +35,9 @@
"egg-multipart": "^2.4.0",
"egg-onerror": "^2.1.0",
"egg-schedule": "^3.6.0",
"egg-security": "^2.4.2",
"egg-security": "^2.4.3",
"egg-session": "^3.1.0",
"egg-static": "^2.1.1",
"egg-static": "^2.2.0",
"egg-view": "^2.1.2",
"egg-watcher": "^3.1.0",
"extend2": "^1.0.0",
Expand Down Expand Up @@ -70,9 +69,9 @@
"egg-plugin-puml": "^2.4.0",
"egg-tracer": "^1.1.0",
"egg-view-nunjucks": "^2.2.0",
"eslint": "^5.13.0",
"eslint": "^5.14.1",
"eslint-config-egg": "^7.1.0",
"findlinks": "^1.1.0",
"findlinks": "^2.0.0",
"formstream": "^1.1.0",
"glob": "^7.1.3",
"koa-static": "^3.0.0",
Expand All @@ -83,7 +82,7 @@
"spy": "^1.0.0",
"supertest": "^3.4.2",
"ts-node": "^3.0.6",
"typescript": "^3.3.3",
"typescript": "^3.3.3333",
"webstorm-disable-index": "^1.1.2"
},
"main": "index.js",
Expand Down
7 changes: 6 additions & 1 deletion test/lib/cluster/cluster-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ describe('test/lib/cluster/cluster-client.test.js', () => {
});
after(async () => {
await app.close();

assert(app.registryClient.isClusterClientLeader);
assert(app.agent.registryClient.isClusterClientLeader);
assert(app.registryClient[innerClient] === app.agent.registryClient[innerClient]);

const agentInnerClient = app.agent.registryClient[innerClient];
assert(agentInnerClient._realClient.closed === true);
assert(agentInnerClient.closed === true);
mm.restore();
});

Expand Down

0 comments on commit db10931

Please sign in to comment.