|
@ -41,10 +41,11 @@ if (cluster.isMaster) { |
|
|
let reqCount = 0; |
|
|
let reqCount = 0; |
|
|
let lastSession = null; |
|
|
let lastSession = null; |
|
|
let shootOnce = false; |
|
|
let shootOnce = false; |
|
|
|
|
|
let workerPort = null; |
|
|
|
|
|
|
|
|
function shoot() { |
|
|
function shoot() { |
|
|
console.error('[master] connecting'); |
|
|
console.error('[master] connecting', workerPort); |
|
|
const c = tls.connect(common.PORT, { |
|
|
const c = tls.connect(workerPort, { |
|
|
session: lastSession, |
|
|
session: lastSession, |
|
|
rejectUnauthorized: false |
|
|
rejectUnauthorized: false |
|
|
}, function() { |
|
|
}, function() { |
|
@ -63,11 +64,12 @@ if (cluster.isMaster) { |
|
|
|
|
|
|
|
|
function fork() { |
|
|
function fork() { |
|
|
const worker = cluster.fork(); |
|
|
const worker = cluster.fork(); |
|
|
worker.on('message', function(msg) { |
|
|
worker.on('message', function({ msg, port }) { |
|
|
console.error('[master] got %j', msg); |
|
|
console.error('[master] got %j', msg); |
|
|
if (msg === 'reused') { |
|
|
if (msg === 'reused') { |
|
|
++reusedCount; |
|
|
++reusedCount; |
|
|
} else if (msg === 'listening' && !shootOnce) { |
|
|
} else if (msg === 'listening' && !shootOnce) { |
|
|
|
|
|
workerPort = port || workerPort; |
|
|
shootOnce = true; |
|
|
shootOnce = true; |
|
|
shoot(); |
|
|
shoot(); |
|
|
} |
|
|
} |
|
@ -99,15 +101,19 @@ const options = { |
|
|
|
|
|
|
|
|
const server = tls.createServer(options, function(c) { |
|
|
const server = tls.createServer(options, function(c) { |
|
|
if (c.isSessionReused()) { |
|
|
if (c.isSessionReused()) { |
|
|
process.send('reused'); |
|
|
process.send({ msg: 'reused' }); |
|
|
} else { |
|
|
} else { |
|
|
process.send('not-reused'); |
|
|
process.send({ msg: 'not-reused' }); |
|
|
} |
|
|
} |
|
|
c.end(); |
|
|
c.end(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
server.listen(common.PORT, function() { |
|
|
server.listen(0, function() { |
|
|
process.send('listening'); |
|
|
const { port } = server.address(); |
|
|
|
|
|
process.send({ |
|
|
|
|
|
msg: 'listening', |
|
|
|
|
|
port, |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
process.on('message', function listener(msg) { |
|
|
process.on('message', function listener(msg) { |
|
|