From edec01fd71918cc16d69deeadebe9a4f2e1490ae Mon Sep 17 00:00:00 2001 From: Joey Guerra Date: Sat, 6 Jan 2024 19:19:14 -0600 Subject: [PATCH] fix the hanging --- benchmarks/README.md | 11 +++++++++++ benchmarks/index.mjs | 28 +++++++++++++--------------- lib/application.js | 2 +- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/benchmarks/README.md b/benchmarks/README.md index e643240c67..f3dec7e076 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -77,3 +77,14 @@ Redesigned Express to not create a prototype chain on the req/res objects. The f | Req/Sec | 56,255 | 56,255 | 64,511 | 66,495 | 63,388.8 | 3,687.84 | 56,241 | | Bytes/Sec | 13.4 MB | 13.4 MB | 15.4 MB | 15.8 MB | 15.1 MB | 877 kB | 13.4 MB | +## Version 3 - 1/6/2024, 7:19:01 PM + +| Stat | 2.5% | 50% | 97.5% | 99% | Avg | Stdev | Max | +|:-----|:----:|:---:|:-----:|:---:|:---:|:-----:|:---:| +| Latency | 8 ms | 18 ms | 20 ms | 22 ms | 15.4 ms | 18.39 ms | 667 ms | + +| Stat | 1% | 2.5% | 50% | 97.5% | Avg | Stdev | Min | +|:-----|:--:|:----:|:---:|:-----:|:---:|:-----:|:---:| +| Req/Sec | 52,095 | 52,095 | 65,439 | 65,855 | 62,758.4 | 5,344.96 | 52,088 | +| Bytes/Sec | 12.4 MB | 12.4 MB | 15.6 MB | 15.7 MB | 14.9 MB | 1.27 MB | 12.4 MB | + diff --git a/benchmarks/index.mjs b/benchmarks/index.mjs index d11329b44e..b07c54555b 100644 --- a/benchmarks/index.mjs +++ b/benchmarks/index.mjs @@ -107,22 +107,20 @@ while (n--) { app.use((req, res) => { res.send('Hello World') }) -app.on('listening', function () { - const { port } = this.address() - autocannon({ - url: `http://localhost:${port}/?foo[bar]=baz`, - pipelining: 10, - connections: 100, - duration: 5, - title: 'Version 3', - workers: 4 - }, (err, result) => { - console.log(toTable(result)) - fs.appendFile(`benchmarks/README.md`, `## ${result.title} - ${new Date().toLocaleString()} +const server = app.listen() +const { port } = server.address() +autocannon({ + url: `http://localhost:${port}/?foo[bar]=baz`, + pipelining: 10, + connections: 100, + duration: 5, + title: 'Version 3', + workers: 4 +}, (err, result) => { + console.log(toTable(result)) + fs.appendFile(`benchmarks/README.md`, `## ${result.title} - ${new Date().toLocaleString()} ${toTable(result)}\n`, 'utf8', () => { - server.close() - }) + server.close() }) }) -const server = app.listen() diff --git a/lib/application.js b/lib/application.js index dea054f54e..fd4dcf19fc 100644 --- a/lib/application.js +++ b/lib/application.js @@ -797,7 +797,7 @@ class ExpressApp extends EventEmitter { listen(...args) { this.#server = http.createServer({ IncomingMessage: ExpressRequest, ServerResponse: ExpressResponse }, this.handle.bind(this)) - return this.#server.listen(...args, () => this.emit('listening')) + return this.#server.listen(...args) } address () { return this.#server?.address() ?? null