-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster.js
More file actions
64 lines (58 loc) · 1.15 KB
/
cluster.js
File metadata and controls
64 lines (58 loc) · 1.15 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const os = require("os");
const cluster = require("cluster");
const startWeb = require("./server");
const {
getConfig,
block,
hash,
read,
requestDns,
requestIP
} = require("./utils");
const cpus = os.cpus().length;
const config = getConfig({
simple: {
// UV_THREADPOOL_SIZE: 1,
clusters: 1,
doWork: block
},
single: {
UV_THREADPOOL_SIZE: 1,
clusters: 1,
doWork: block
},
cluster: {
UV_THREADPOOL_SIZE: 1,
clusters: 4,
doWork: block
},
cpus: {
UV_THREADPOOL_SIZE: 1,
clusters: cpus,
doWork: hash
},
"cpus-2": {
UV_THREADPOOL_SIZE: 1,
clusters: cpus - 2,
doWork: hash
},
"2*cpus": {
UV_THREADPOOL_SIZE: 1,
clusters: cpus * 2,
doWork: hash
}
});
const { UV_THREADPOOL_SIZE, clusters, doWork } = config;
if (UV_THREADPOOL_SIZE) {
process.env.UV_THREADPOOL_SIZE = UV_THREADPOOL_SIZE;
}
if (cluster.isMaster) {
console.log(`CPUs: ${cpus}`);
console.log(`UV_THREADPOOL_SIZE: ${process.env.UV_THREADPOOL_SIZE || 4}`);
console.log(`clusters: ${clusters}`);
for (let i = 0; i < clusters; i++) {
cluster.fork();
}
} else {
startWeb(doWork, cluster.worker);
}