Skip to content

Instantly share code, notes, and snippets.

@geta6
Last active December 10, 2015 22:38
Show Gist options
  • Save geta6/4503329 to your computer and use it in GitHub Desktop.
Save geta6/4503329 to your computer and use it in GitHub Desktop.
# _人人人人人人人人人人_
# > 圧倒的な分散性能 <
#  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄
cluster = require 'cluster'
cpunums = (require 'os').cpus().length
workers = {}
global._ = require 'underscore'
if cluster.isMaster
killall = (msg) ->
return (msg) ->
console.warn ":;(∩´﹏` ∩);: Killing with received #{msg}"
_.each workers, (worker) ->
worker.kill()
console.warn "(。ŏ﹏ŏ。) Worker died #{worker.pid}"
console.warn "(^O^) Shutting down master process"
process. exit 1
for i in [0...cpunums]
worker = cluster.fork()
workers[worker.process.pid] = worker
process.on 'uncaughtException', killall 'uncaught exception'
process.on 'exit', killall 'exit'
cluster.on 'death', (worker, code, signal) ->
cluster.fork()
console.warn "( ꒪⌓꒪) Worker #{worker.process.pid} died"
else
server = (require 'http').createServer (req, res) ->
res.writeHead 200, 'Content-Type': 'text/plain'
res.end 'OK'
server.listen 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment