This file contains 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
cluster.on('online', (worker) => log(`Worker ${worker.process.pid} is online`)) | |
cluster.on('exit', (worker, exitCode) => { | |
log(`Worker ${worker.process.id} exited with code ${exitCode}`) | |
log(`Starting a new worker`) | |
cluster.fork() | |
} |
This file contains 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
let workers = [] | |
for(let i = 0; i < numWorkers; i++) { | |
workers.push(cluster.fork()) | |
} |
This file contains 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 { cpus } = require('os') | |
const numWorkers = cpus().length | |
const isMaster = cluster.isMaster | |
if (isMaster) { | |
process.stdout.write('I am master!') | |
const workers = [...Array(numWorkers)].map(_ => cluster.fork()) | |
This file contains 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 isMaster = cluster.isMaster |
This file contains 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') |
This file contains 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 { cpus } = require('os') | |
const numWorkers = cpus().length |
This file contains 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 { cpus } = require('os') | |
const log = require('./modules/log') | |
const isMaster = cluster.isMaster | |
const numWorkers = cpus().length | |
if (isMaster) { | |
log(`Forking ${numWorkers} workers`) |
This file contains 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
defmodule Processes do | |
alias __MODULE__ | |
def sendRequest url do | |
case HTTPoison.post url, [], [], [timeout: 50_000, recv_timeout: 50_000] do | |
{:ok, %HTTPoison.Response{status_code: 200, headers: headers}} | |
-> IO.inspect headers | |
{:error, %HTTPoison.Error{reason: reason}} | |
-> IO.inspect {:error, reason} | |
end |
This file contains 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 Koa = require('koa') | |
const Router = require('koa-router') | |
const runJob = require('./modules/job') | |
const log = require('./modules/log') | |
const router = new Router() | |
const app = new Koa() | |
router.get('/', async ctx => ctx.body = `PID ${process.pid} listening here!`) | |
.post('/flip', async ctx => { | |
const res = await runJob() |
This file contains 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 fs = require('fs') | |
const jimp = require('jimp') | |
const log = require('./log') | |
module.exports = function runJob() { | |
return new Promise(async (resolve, reject) => { | |
const randomNumber = () => Math.floor(Math.random() * 1995) * 15 | |
const destFileName = `${__dirname}/../imgs/dest/${randomNumber()}-img.jpg` |