-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathstart.coffee
More file actions
34 lines (31 loc) · 995 Bytes
/
start.coffee
File metadata and controls
34 lines (31 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
cluster = require 'cluster'
os = require 'os'
http = require 'http'
numCPUs = os.cpus()
workerList = []
createWorker = () ->
worker = cluster.fork()
worker.on "message", (data) ->
console.log "the worker " + worker.id + "|" + worker.process.pid + " accept data: " + JSON.stringify(data)
if data.type and data.type is "broadcast"
workerList.forEach (wk) ->
wk.send data.body
return
return
return worker;
if cluster.isMaster
console.log "master process start..."
for i in numCPUs
workerList.push createWorker()
cluster.on 'listening', (worker, address) ->
console.log "A worker with #" + worker.id + " pid " + worker.process.pid +
" is now connected to " + address.address + ":" + address.port
return
cluster.on 'exit', (worker, code, signal) ->
console.log 'worker ' + worker.process.pid + ' died'
process.nextTick () ->
cluster.fork();
return
return
else
require './app.coffee'