-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread-pool.js
58 lines (51 loc) · 1.18 KB
/
thread-pool.js
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
const fs = require('fs');
const crypto = require('crypto');
const http = require('http');
process.env.UV_THREADPOOL_SIZE = 5
const start = Date.now();
function getTime(start) {
return ((Date.now() - start) / 1000) + "s"
}
function request() {
return new Promise(resolve => {
http.request("http://localhost:3000", res => {
res.on('data', () => {})
res.on('end', () => {
console.log('Request --> ', getTime(start))
resolve();
})
}).end();
});
}
function readFile() {
return new Promise(resolve => {
fs.readFile('text.txt', 'utf8', () => {
console.log('Read file --> ', getTime(start))
resolve();
})
})
}
function hash() {
return new Promise(resolve => {
crypto.pbkdf2("some", "thing", 100000, 512, 'sha512', () => {
console.log('Hash --> ', getTime(start))
resolve();
})
})
}
Promise.all([
// readFile(),
hash(1),
hash(2),
hash(3),
hash(4),
request(5),
request(6),
request(7),
request(8),
request(9),
request(10),
request(11),
request(12),
request(13),
])