diff --git a/app.json b/app.json index bf26783ab..7339a5f17 100644 --- a/app.json +++ b/app.json @@ -10,10 +10,6 @@ "description": "The shared secret to use to sign JSON Web Tokens (JWT) with the selected signing algorithm.", "generator": "secret" }, - "CONCURRENCY": { - "description": "The number of worker nodes to spawn to handle traffic.", - "value": "1" - }, "LOCALE": { "description": "Specify the default locale to use for all requests without a locale specified", "value": "en-US" diff --git a/package-lock.json b/package-lock.json index 587fcff30..7f3c644c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8261,12 +8261,6 @@ "integrity": "sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==", "dev": true }, - "@types/throng": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@types/throng/-/throng-4.0.2.tgz", - "integrity": "sha512-7tgh3R6vwtjj01URmhWXFSkWnm4wDJjsqLm8WPwIWadYjfsKAFi0HqabMQCU2JJ4TbeSGkb51qv27bBPN5Bubw==", - "dev": true - }, "@types/tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/@types/tmp/-/tmp-0.0.33.tgz", @@ -48699,14 +48693,6 @@ "integrity": "sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==", "dev": true }, - "throng": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/throng/-/throng-4.0.0.tgz", - "integrity": "sha1-mDxroZk7WOroWZmKpof/6I34TBc=", - "requires": { - "lodash.defaults": "^4.0.1" - } - }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", diff --git a/package.json b/package.json index a37942987..151d2ab61 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "generate:schema": "node ./scripts/generateSchemaTypes.js", "docz": "docz", "start": "NODE_ENV=production node dist/index.js", - "start:development": "NODE_ENV=development CONCURRENCY=${CONCURRENCY:-1} TS_NODE_PROJECT=./src/tsconfig.json ts-node-dev --inspect --transpile-only --no-notify -r tsconfig-paths/register ./src/index.ts", + "start:development": "NODE_ENV=development TS_NODE_PROJECT=./src/tsconfig.json ts-node-dev --inspect --transpile-only --no-notify -r tsconfig-paths/register ./src/index.ts", "start:webpackDevServer": "ts-node --transpile-only ./scripts/start.ts", "lint": "npm-run-all --parallel lint:* tscheck:*", "lint:server": "eslint 'src/**/*.{js,ts,tsx}' --ignore-pattern 'src/core/client/**'", @@ -135,7 +135,6 @@ "source-map-support": "^0.5.16", "stack-utils": "^2.0.1", "striptags": "^3.1.1", - "throng": "^4.0.0", "tsscmp": "^1.0.6", "url-regex": "^5.0.0", "uuid": "^7.0.3", @@ -227,7 +226,6 @@ "@types/source-map-support": "^0.5.1", "@types/stack-trace": "0.0.29", "@types/stack-utils": "^1.0.1", - "@types/throng": "^4.0.2", "@types/uuid": "^7.0.2", "@types/verror": "^1.10.3", "@types/vinyl": "^2.0.4", diff --git a/src/core/server/app/index.ts b/src/core/server/app/index.ts index 3659a6545..14abe9118 100644 --- a/src/core/server/app/index.ts +++ b/src/core/server/app/index.ts @@ -9,7 +9,7 @@ import http from "http"; import { Db } from "mongodb"; import nunjucks from "nunjucks"; import path from "path"; -import { AggregatorRegistry, register } from "prom-client"; +import { register } from "prom-client"; import { cacheHeadersMiddleware, @@ -224,34 +224,11 @@ export default function createMetricsServer(config: Config) { ); } - // If we are running in concurrency mode, we should setup the aggregator for - // the cluster metrics. - if (config.get("concurrency") > 1) { - // Create the aggregator registry for metrics. - const aggregatorRegistry = new AggregatorRegistry(); - - // Use the aggregator registry to handle serving metrics. - server.get("/cluster_metrics", (req, res, next) => { - aggregatorRegistry.clusterMetrics((err, metrics) => { - if (err) { - return next(err); - } - - res.set("Content-Type", aggregatorRegistry.contentType); - res.send(metrics); - }); - }); - - logger.info({ path: "/cluster_metrics" }, "mounted metrics handler"); - } else { - // Use the memory register to handle serving metrics. - server.get("/metrics", (req, res) => { - res.set("Content-Type", register.contentType); - res.end(register.metrics()); - }); - - logger.info({ path: "/metrics" }, "mounted metrics handler"); - } + // Use the memory register to handle serving metrics. + server.get("/metrics", (req, res) => { + res.set("Content-Type", register.contentType); + res.end(register.metrics()); + }); // Error handling. server.use(notFoundMiddleware); diff --git a/src/core/server/config.ts b/src/core/server/config.ts index 1723950cf..b12e77e64 100644 --- a/src/core/server/config.ts +++ b/src/core/server/config.ts @@ -2,7 +2,6 @@ import Joi from "@hapi/joi"; import convict from "convict"; import { parseConnectionString } from "mongodb-core"; import ms from "ms"; -import os from "os"; import { LOCALES } from "coral-common/helpers/i18n/locales"; import { ensureEndSlash } from "coral-common/utils"; @@ -95,12 +94,6 @@ const config = convict({ default: false, env: "ENABLE_GRAPHIQL", }, - concurrency: { - doc: "The number of worker nodes to spawn to handle traffic", - format: Number, - default: os.cpus().length, - env: "CONCURRENCY", - }, port: { doc: "The port to bind.", format: "port", @@ -137,7 +130,6 @@ const config = convict({ format: "mongo-uri", default: "mongodb://127.0.0.1:27017/coral", env: "MONGODB_URI", - sensitive: true, }, redis: { @@ -145,7 +137,6 @@ const config = convict({ format: "redis-uri", default: "redis://127.0.0.1:6379", env: "REDIS_URI", - sensitive: true, }, redis_options: { @@ -160,7 +151,6 @@ const config = convict({ format: "*", default: "keyboard cat", // TODO: (wyattjoh) evaluate best solution env: "SIGNING_SECRET", - sensitive: true, }, signing_algorithm: { @@ -174,7 +164,6 @@ const config = convict({ format: "*", default: null, env: "MANAGEMENT_SIGNING_SECRET", - sensitive: true, }, management_signing_algorithm: { diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 0c1f72763..f677d9c06 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -1,4 +1,3 @@ -import cluster from "cluster"; import express, { Express } from "express"; import { GraphQLSchema } from "graphql"; import { RedisPubSub } from "graphql-redis-subscriptions"; @@ -273,14 +272,10 @@ class Server { signingConfig: this.signingConfig, }); - // We only want to setup a metrics server iff the concurrency is 1 or the - // concurrency is greater than one and this is the master process. - if (config.get("concurrency") === 1 || cluster.isMaster) { - // Configure the metrics server and start it. - const port = this.config.get("metrics_port"); - await listenAndServe(createMetricsServer(this.config), port); - logger.info({ port }, "now listening for metrics"); - } + // Configure the metrics server and start it. + const port = this.config.get("metrics_port"); + await listenAndServe(createMetricsServer(this.config), port); + logger.info({ port, path: "/metrics" }, "now listening for metrics"); } /** diff --git a/src/core/server/logger/index.ts b/src/core/server/logger/index.ts index aff4632f4..77db78a9a 100644 --- a/src/core/server/logger/index.ts +++ b/src/core/server/logger/index.ts @@ -1,5 +1,4 @@ import bunyan, { LogLevelString } from "bunyan"; -import cluster from "cluster"; import config from "coral-server/config"; @@ -11,9 +10,6 @@ export type Logger = ReturnType; const logger = bunyan.createLogger({ name: "coral", - // Attach the cluster node information to the log entries. - clusterNode: cluster.worker ? `worker.${cluster.worker.id}` : "master", - // Include file references in log entries. src: true, serializers, diff --git a/src/index.ts b/src/index.ts index ff4067fea..b6366a44b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,44 +29,13 @@ process.on("unhandledRejection", (err) => { }); import express from "express"; -import throng from "throng"; import createCoral from "./core"; -import Server from "./core/server"; import logger from "./core/server/logger"; // Create the app that will serve as the mounting point for the Coral Server. const parent = express(); -// worker will start the worker process. -async function worker(server: Server) { - try { - // Start the server. - await server.start({ parent }); - - logger.debug("started server worker"); - } catch (err) { - logger.error({ err }, "can not start server in worker mode"); - throw err; - } -} - -// master will start the master process. -async function master(server: Server) { - const workerCount = server.config.get("concurrency"); - logger.debug({ workerCount }, "spawning workers to handle traffic"); - - try { - // Process jobs. - await server.process(); - - logger.debug("started server master"); - } catch (err) { - logger.error({ err }, "can not start server in master mode"); - throw err; - } -} - // bootstrap will create a new Coral server, and start it up. async function bootstrap() { try { @@ -75,31 +44,14 @@ async function bootstrap() { // Create the server instance. const server = createCoral(); - // Determine the number of workers. - const workerCount = server.config.get("concurrency"); - // Connect the server to databases. await server.connect(); - if (workerCount === 1) { - logger.debug( - { workerCount }, - "not utilizing cluster as concurrency level is 1" - ); + // Start processing jobs. + await server.process(); - // Start processing jobs. - await server.process(); - - // Start the server. - await server.start({ parent }); - } else { - // Launch the server start within throng. - throng({ - workers: workerCount, - start: () => worker(server), - master: () => master(server), - }); - } + // Start the server. + await server.start({ parent }); } catch (err) { logger.error({ err }, "can not bootstrap server"); throw err;