Skip to content

Commit be62a57

Browse files
committed
adding cluster example
1 parent fb7dc58 commit be62a57

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

benchmark/gateway-cluster.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict'
2+
3+
const cluster = require('cluster')
4+
5+
if (cluster.isMaster) {
6+
const cpuCount = 4
7+
for (let i = 0; i < cpuCount; i++) {
8+
cluster.fork()
9+
}
10+
} else {
11+
const gateway = require('../index')
12+
13+
const server = gateway({
14+
routes: [{
15+
prefix: '/service',
16+
target: 'http://127.0.0.1:3000'
17+
}]
18+
})
19+
20+
server.start(8080)
21+
}
22+
23+
cluster.on('exit', (worker) => {
24+
cluster.fork()
25+
})

0 commit comments

Comments
 (0)