From 66aef07e9c580605b375cee824d60f5af4e57412 Mon Sep 17 00:00:00 2001 From: Micooz Date: Mon, 14 Aug 2017 17:39:37 +0800 Subject: [PATCH] core: disable cluster mode by default --- bin/init.js | 5 ++--- docs/config/README.md | 22 ++++++++++++++++++---- src/core/config.js | 4 ++-- src/core/constants.js | 4 +--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/bin/init.js b/bin/init.js index 6826b5e..8683d6f 100644 --- a/bin/init.js +++ b/bin/init.js @@ -30,7 +30,6 @@ module.exports = function init() { const key = random('abcdefghjkmnpqrstuvwxyz23456789!@#$%^&*()_+<>?:|{}-=[];,./ABCDEFGHJKLMNPQRSTUVWXYZ', 16); const port = getRandomInt(1024, 65535); const timeout = getRandomInt(200, 1000); - const workers = os.cpus().length; const clientJson = { 'host': '127.0.0.1', @@ -59,7 +58,7 @@ module.exports = function init() { 'dns': [], 'dns_expire': 3600, 'timeout': timeout, - 'workers': workers, + 'workers': 0, 'log_level': 'info' }; @@ -84,7 +83,7 @@ module.exports = function init() { 'dns_expire': 3600, 'redirect': '', 'timeout': timeout, - 'workers': workers, + 'workers': 0, 'log_level': 'info' }; diff --git a/docs/config/README.md b/docs/config/README.md index b06d9b7..d7ee3a8 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -57,8 +57,8 @@ $ blinksocks init "dns_expire": 3600, // close inactive connection after timeout seconds "timeout": 600, - // how many sub processes to create, default is the number of CPU cores, 0 to disable cluster mode - "workers": 2, + // how many sub processes to create, default is 0(disable cluster mode) + "workers": 0, // log at the level, "error", "warn", "info", "verbose", "debug" or "silly" "log_level": "info" } @@ -105,8 +105,8 @@ $ blinksocks init "redirect": "", // close inactive connection after timeout seconds "timeout": 600, - // how many sub processes to create, default is the number of CPU cores, 0 to disable cluster mode - "workers": 2, + // how many sub processes to create, default is 0(disable cluster mode) + "workers": 0, // log at the level, "error", "warn", "info", "verbose", "debug" or "silly" "log_level": "info" } @@ -186,3 +186,17 @@ If you encounter **ENOTFOUND** every now and then, you would better custom dns s If no `dns` option or no ip provided in `dns`, blinksocks use system dns settings as usual. See: https://github.com/blinksocks/blinksocks/issues/66 + +## Cluster Mode + +You can enable cluster mode by setting `workers` greater than zero, cluster mode can take advantage of multi-core systems to handle the load. + +`workers` is usually set to the number of cpu cores: + +``` +{ + ... + "workers": 2 + ... +} +``` diff --git a/src/core/config.js b/src/core/config.js index 61966a6..45c29b6 100755 --- a/src/core/config.js +++ b/src/core/config.js @@ -3,7 +3,7 @@ import fs from 'fs'; import os from 'os'; import net from 'net'; import {isValidPort} from '../utils'; -import {BLINKSOCKS_DIR, LOG_DIR, DEFAULT_LOG_LEVEL, DEFAULT_WORKERS} from './constants'; +import {BLINKSOCKS_DIR, LOG_DIR, DEFAULT_LOG_LEVEL} from './constants'; import {DNS_DEFAULT_EXPIRE} from './dns-cache'; /** @@ -202,7 +202,7 @@ export class Config { global.__IS_SERVER__ = !global.__IS_CLIENT__; global.__REDIRECT__ = json.redirect; global.__TIMEOUT__ = json.timeout * 1e3; - global.__WORKERS__ = (json.workers !== undefined) ? json.workers : DEFAULT_WORKERS; + global.__WORKERS__ = (json.workers !== undefined) ? json.workers : 0; global.__LOG_LEVEL__ = json.log_level || DEFAULT_LOG_LEVEL; global.__DNS_EXPIRE__ = (json.dns_expire !== undefined) ? json.dns_expire * 1e3 : DNS_DEFAULT_EXPIRE; global.__ALL_CONFIG__ = json; diff --git a/src/core/constants.js b/src/core/constants.js index 86d3565..e2ca751 100644 --- a/src/core/constants.js +++ b/src/core/constants.js @@ -15,7 +15,6 @@ const LOG_FILE_PATH = path.join(LOG_DIR, ); const LOG_FILE_MAX_SIZE = 2 * 1024 * 1024; // 2MB const DEFAULT_LOG_LEVEL = 'info'; -const DEFAULT_WORKERS = os.cpus().length; module.exports = { HOME_DIR, @@ -23,6 +22,5 @@ module.exports = { LOG_DIR, LOG_FILE_PATH, LOG_FILE_MAX_SIZE, - DEFAULT_LOG_LEVEL, - DEFAULT_WORKERS + DEFAULT_LOG_LEVEL };