Skip to content

Instantly share code, notes, and snippets.

View c4x1's full-sized avatar
๐ŸŒ€
home->work->home->work;

CSpornov c4x1

๐ŸŒ€
home->work->home->work;
  • Russian
View GitHub Profile
@c4x1
c4x1 / 1564835567.js
Last active August 3, 2019 12:33
NodeJS: SharedMemory: ั€ะฐะทะดะตะปะตะฝะธะต ะฟะฐะผัั‚ะธ ะฝะฐ ะบะฐะถะดะพะผ ั€ะฐะฑะพั‚ะฝะธะบะต ะบะปะฐัั‚ะตั€ะฐ
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
//
// ** SharedMemory which is shared among every worker:
//
// dont use `var`
SharedMemory = {
// shared data:
@c4x1
c4x1 / gist:770460d21d24dbea9306ec01b6ae4f6f
Created August 3, 2019 12:14 — forked from alekseydreval/gist:21a8c89c9f7f3519a477
Node.js cluster recursive startup
# 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")
@c4x1
c4x1 / 1564834327.js
Created August 3, 2019 12:12
Created with Copy to Gist
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}'`);
@c4x1
c4x1 / 1564834214.js
Created August 3, 2019 12:10
Created with Copy to Gist
// 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:
//
@c4x1
c4x1 / cluster.js
Created August 3, 2019 11:48 — forked from bennadel/cluster.js
Hello World: Concurrency In Node.js Using The Cluster Module
// 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
@c4x1
c4x1 / back.ts
Created August 3, 2019 10:58 — forked from syuilo/back.ts
AI
/**
* -AI-
* Botใฎใƒใƒƒใ‚ฏใ‚จใƒณใƒ‰(ๆ€่€ƒใ‚’ๆ‹…ๅฝ“)
*
* ๅฏพ่ฉฑใจๆ€่€ƒใ‚’ๅŒใ˜ใƒ—ใƒญใ‚ปใ‚นใง่กŒใ†ใจใ€ๆ€่€ƒๆ™‚้–“ใŒ้•ทๅผ•ใ„ใŸใจใใซใ‚นใƒˆใƒชใƒผใƒ ใ‹ใ‚‰
* ๅˆ‡ๆ–ญใ•ใ‚Œใฆใ—ใพใ†ใฎใงใ€ๅˆฅใ€…ใฎใƒ—ใƒญใ‚ปใ‚นใง่กŒใ†ใ‚ˆใ†ใซใ—ใพใ™
*/
import Othello, { Color } from '../core';
@c4x1
c4x1 / watch.js
Last active August 3, 2019 10:57
Created with Copy to Gist
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';
@c4x1
c4x1 / fork_process.ts
Last active August 3, 2019 10:52
claster++express.router()
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");
@c4x1
c4x1 / 1564828618.js
Created August 3, 2019 10:37
Created with Copy to Gist
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).
*
@c4x1
c4x1 / ForkBalancer.ts
Last active August 3, 2019 10:33
Created with Copy to Gist
import { ChildProcess, fork } from 'child_process';
import config from '../config';
const { requestLimit } = config;
interface forkResponse {
kill: boolean;
string?: string;
}