-
-
Save Jarred-Sumner/bc5fc8e092f2036c396e8fb507a9f3c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const server = process.argv.at(-1); | |
const fmt = new Intl.NumberFormat(); | |
let total = 0; | |
const batch = 50; | |
const delay = 0; | |
while (true) { | |
const array = new Array(batch); | |
for (let i = 0; i < batch; i++) { | |
array[i] = fetch(server); | |
} | |
await Promise.all(array); | |
await new Promise((r) => setTimeout(r, delay)); | |
console.log( | |
"RSS", | |
(process.memoryUsage.rss() / 1024 / 1024) | 0, | |
"MB after", | |
fmt.format((total += batch)) + " fetch() requests" | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const blob = new Blob([require("crypto").randomFillSync( new Uint8Array(1024 * 512))]); | |
Bun.serve({ | |
fetch(req) { | |
return new Response(blob); | |
}, | |
port: process.argv.at(-1), | |
}); |
Also, if you change the fetch call to await the body of the response, then bun/deno/node20/21 all behave pretty much the same but node.js uses ~30% less memory (150 MB) than deno or bun (both around 210 MB) on ubuntu 22.04.
array[i] = fetch(server).then(res => res.text());
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this code will work on deno too. seems to perform pretty much the same as bun, but with some strange occasional stalls on my setup. defo see the same issue as you with node.js versions 20 and 21. memory keeps growing and never gets released, even if i force gc on every iteration of the loop.