feat: added concurrency features

This commit is contained in:
Wyatt Johnson
2018-12-19 12:40:08 -07:00
parent 08f579225b
commit ec816636e6
5 changed files with 30 additions and 7 deletions
+17 -5
View File
@@ -1,8 +1,10 @@
#!/usr/bin/env node
const throng = require('throng');
const { CONCURRENCY } = require('../config');
const { logger } = require('../services/logging');
const util = require('./util');
const program = require('commander');
const serve = require('../serve');
//==============================================================================
// Setting up the program command line arguments.
@@ -22,8 +24,18 @@ program
)
.parse(process.argv);
// Start serving.
serve(program).catch(err => {
console.error(err);
util.shutdown(1);
throng({
workers: CONCURRENCY,
start: i => {
logger.info({ workerID: i }, 'started worker');
// Load in the serve.
const serve = require('../serve');
// Start serving.
serve(program).catch(err => {
console.error(err);
util.shutdown(1);
});
},
});
+3
View File
@@ -217,6 +217,9 @@ const CONFIG = {
// messages through the websocket to keep the socket alive.
KEEP_ALIVE: process.env.TALK_KEEP_ALIVE || '30s',
// CONCURRENCY is the number of workers that will serve traffic.
CONCURRENCY: parseInt(process.env.TALK_CONCURRENCY || '1'),
//------------------------------------------------------------------------------
// Cache configuration
//------------------------------------------------------------------------------
+1
View File
@@ -205,6 +205,7 @@
"style-loader": "^0.16.0",
"subscriptions-transport-ws": "^0.7.2",
"supports-color": "^4",
"throng": "^4.0.0",
"timeago.js": "^2.0.3",
"timekeeper": "^1.0.0",
"tlds": "^1.196.0",
+2 -2
View File
@@ -91,12 +91,12 @@ class Task {
static shutdown() {
debug('Shutting down the Queue');
return new Promise((resolve, reject) => {
return new Promise(resolve => {
// Shutdown and give the queue 5 seconds to shutdown before we start
// killing jobs.
getQueue().shutdown(5000, err => {
if (err) {
return reject(err);
return resolve();
}
debug('Queue shut down.');
+7
View File
@@ -12823,6 +12823,13 @@ throat@^4.0.0:
resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a"
integrity sha1-iQN8vJLFarGJJua6TLsgDhVnKmo=
throng@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/throng/-/throng-4.0.0.tgz#983c6ba1993b58eae859998aa687ffe88df84c17"
integrity sha1-mDxroZk7WOroWZmKpof/6I34TBc=
dependencies:
lodash.defaults "^4.0.1"
through2@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.3.tgz#0004569b37c7c74ba39c43f3ced78d1ad94140be"