-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.js
More file actions
22 lines (18 loc) · 619 Bytes
/
fetch.js
File metadata and controls
22 lines (18 loc) · 619 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const { fetch, setGlobalDispatcher, Agent } = require('undici')
const parallelRequests = 1000
const samples = 100
function makeParallelRequests (cb) {
return Promise.all(Array.from(Array(parallelRequests)).map(() => new Promise(cb)))
}
async function main() {
setGlobalDispatcher(new Agent({ connections: 50 }))
console.time('fetch')
for (let i = 0; i < samples; ++i) {
await makeParallelRequests(async (resolve) => {
const res = await fetch('http://localhost:3000')
res.body.pipeTo(new WritableStream({ write () {}, close () { resolve() } }))
})
}
console.timeEnd('fetch')
}
main()