This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const cluster = require('cluster'); | |
| const numCPUs = require('os').cpus().length; | |
| // | |
| // ** SharedMemory which is shared among every worker: | |
| // | |
| // dont use `var` | |
| SharedMemory = { | |
| // shared data: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # clustering | |
| cluster = require "cluster" | |
| process.execPath = "coffee" | |
| os = require("os") | |
| numCPU = os.cpus().length | |
| platform = os.platform() | |
| # logger | |
| winston = require("./lib/utils/logger.coffee")("server.coffee") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| else { | |
| // Docs: send a message to the master. | |
| console.log(`<-- worker${cluster.worker.id} sending message -->`); | |
| // These two are identical. | |
| //cluster.worker.send(`message from worker ${cluster.worker.id} (via cluster.worker.send)`); | |
| process.send(`message from worker ${cluster.worker.id} (via process.send)`); | |
| // These two are also identical: | |
| process.on("message", function (message) { | |
| console.log(`worker[${cluster.worker.id}]: (process.onMessage) '${message}'`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright Joyent, Inc. and other Node contributors. | |
| // | |
| // Permission is hereby granted, free of charge, to any person obtaining a | |
| // copy of this software and associated documentation files (the | |
| // "Software"), to deal in the Software without restriction, including | |
| // without limitation the rights to use, copy, modify, merge, publish, | |
| // distribute, sublicense, and/or sell copies of the Software, and to permit | |
| // persons to whom the Software is furnished to do so, subject to the | |
| // following conditions: | |
| // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Require the core node modules. | |
| var chalk = require( "chalk" ); | |
| var cluster = require( "cluster" ); | |
| var os = require( "os" ); | |
| // ----------------------------------------------------------------------------------- // | |
| // ----------------------------------------------------------------------------------- // | |
| // The cluster module in Node.js works by executing the application entry-point | |
| // multiple and sharing the master ports with the worker ports. As such, this code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * -AI- | |
| * Botใฎใใใฏใจใณใ(ๆ่ใๆ ๅฝ) | |
| * | |
| * ๅฏพ่ฉฑใจๆ่ใๅใใใญใปในใง่กใใจใๆ่ๆ้ใ้ทๅผใใใจใใซในใใชใผใ ใใ | |
| * ๅๆญใใใฆใใพใใฎใงใๅฅใ ใฎใใญใปในใง่กใใใใซใใพใ | |
| */ | |
| import Othello, { Color } from '../core'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sane from 'sane'; | |
| import { resolve as resolvePath } from 'path'; | |
| import { spawn, fork } from 'child_process'; | |
| import { existsSync as fileExists} from 'fs'; | |
| import { | |
| red, green, yellow, blue, | |
| magenta, cyan, white, gray | |
| } from 'chalk'; | |
| process.env.PATH += ':./node_modules/.bin'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Request, Response, Router } from "express"; | |
| import * as fs from "fs"; | |
| import * as child from "child_process"; | |
| export class HeavyController { | |
| public router: Router = Router(); | |
| constructor() { | |
| this.router.get("/", (req: Request, res: Response) => { | |
| const copute = child.fork("./src/controllers/compute.ts"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cluster = require('cluster'), | |
| http = require('http'), | |
| os = require('os'), | |
| /* | |
| * ClusterServer object | |
| * | |
| * We start multi-threaded server instances by passing the server object | |
| * to ClusterServer.start(server, port). | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ChildProcess, fork } from 'child_process'; | |
| import config from '../config'; | |
| const { requestLimit } = config; | |
| interface forkResponse { | |
| kill: boolean; | |
| string?: string; | |
| } |