| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9b1a379 commit 12c1ac4
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,27 +5,27 @@ | |||
| 5 | 5 | const common = require('../common'); | |
| 6 | 6 | const onGC = require('../common/ongc'); | |
| 7 | 7 | ||
| 8 | + const cpus = require('os').cpus().length; | ||
| 9 | + | ||
| 8 | 10 | function serverHandler(req, res) { | |
| 9 | 11 | res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
| 10 | 12 | res.end('Hello World\n'); | |
| 11 | 13 | } | |
| 12 | 14 | ||
| 13 | 15 | const http = require('http'); | |
| 14 | - const todo = 300; | ||
| 16 | + let createClients = true; | ||
| 15 | 17 | let done = 0; | |
| 16 | 18 | let count = 0; | |
| 17 | 19 | let countGC = 0; | |
| 18 | 20 | ||
| 19 | - console.log(`We should do ${todo} requests`); | ||
| 20 | - | ||
| 21 | 21 | const server = http.createServer(serverHandler); | |
| 22 | 22 | server.listen(0, common.mustCall(() => { | |
| 23 | - for (let i = 0; i < 15; i++) | ||
| 24 | - getall(); | ||
| 23 | + for (let i = 0; i < cpus; i++) | ||
| 24 | + getAll(); | ||
| 25 | 25 | })); | |
| 26 | 26 | ||
| 27 | - function getall() { | ||
| 28 | - if (count === todo) | ||
| 27 | + function getAll() { | ||
| 28 | + if (!createClients) | ||
| 29 | 29 | return; | |
| 30 | 30 | ||
| 31 | 31 | const req = http.get({ | |
@@ -37,7 +37,7 @@ function getall() { | |||
| 37 | 37 | count++; | |
| 38 | 38 | onGC(req, { ongc }); | |
| 39 | 39 | ||
| 40 | - setImmediate(getall); | ||
| 40 | + setImmediate(getAll); | ||
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | 43 | function cb(res) { | |
@@ -49,11 +49,19 @@ function ongc() { | |||
| 49 | 49 | countGC++; | |
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | - setInterval(status, 100).unref(); | ||
| 52 | + setImmediate(status); | ||
| 53 | 53 | ||
| 54 | 54 | function status() { | |
| 55 | - global.gc(); | ||
| 56 | - console.log('Done: %d/%d', done, todo); | ||
| 57 | - console.log('Collected: %d/%d', countGC, count); | ||
| 58 | - if (countGC === todo) server.close(); | ||
| 55 | + if (done > 0) { | ||
| 56 | + createClients = false; | ||
| 57 | + global.gc(); | ||
| 58 | + console.log(`done/collected/total: ${done}/${countGC}/${count}`); | ||
| 59 | + if (countGC === count) { | ||
| 60 | + server.close(); | ||
| 61 | + } else { | ||
| 62 | + setImmediate(status); | ||
| 63 | + } | ||
| 64 | + } else { | ||
| 65 | + setImmediate(status); | ||
| 66 | + } | ||
| 59 | 67 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments