Last active
December 10, 2015 22:38
-
-
Save geta6/4503329 to your computer and use it in GitHub Desktop.
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
# _人人人人人人人人人人_ | |
# > 圧倒的な分散性能 < | |
#  ̄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