Repository navigation
http: significant performance regression on master #37937
Copy link
Copy link
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
Description
- Version: master vs v14 and v15
- Platform: linux
- Subsystem: http
What steps will reproduce the bug?
run:
'use strict'
const server = require('http').createServer(function (req, res) {
res.setHeader('content-type', 'application/json; charset=utf-8')
res.end(JSON.stringify({ hello: 'world' }))
})
server.listen(3000)and then:
$ npm i autocannon -g
$ autocannon -c 100 -d 5 -p 10 localhost:3000
on v14.16 this produces:
$ autocannon -c 100 -d 5 -p 10 localhost:3000
Running 5s test @ http://localhost:3000
100 connections with 10 pipelining factor
┌─────────┬──────┬───────┬───────┬───────┬──────────┬─────────┬────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼──────┼───────┼───────┼───────┼──────────┼─────────┼────────┤
│ Latency │ 5 ms │ 13 ms │ 21 ms │ 27 ms │ 13.05 ms │ 5.93 ms │ 129 ms │
└─────────┴──────┴───────┴───────┴───────┴──────────┴─────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Req/Sec │ 60543 │ 60543 │ 77439 │ 78079 │ 73916.8 │ 6747.59 │ 60531 │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Bytes/Sec │ 11.3 MB │ 11.3 MB │ 14.5 MB │ 14.6 MB │ 13.8 MB │ 1.26 MB │ 11.3 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘
Req/Bytes counts sampled once per second.
370k requests in 5.04s, 69.1 MB read
on master:
$ autocannon -c 100 -d 5 -p 10 localhost:3000
Running 5s test @ http://localhost:3000
100 connections with 10 pipelining factor
┌─────────┬───────┬───────┬───────┬───────┬──────────┬─────────┬────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼───────┼───────┼───────┼───────┼──────────┼─────────┼────────┤
│ Latency │ 10 ms │ 14 ms │ 29 ms │ 54 ms │ 16.83 ms │ 8.54 ms │ 163 ms │
└─────────┴───────┴───────┴───────┴───────┴──────────┴─────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Req/Sec │ 43007 │ 43007 │ 61151 │ 62143 │ 57724.8 │ 7388.63 │ 42988 │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Bytes/Sec │ 8.04 MB │ 8.04 MB │ 11.4 MB │ 11.6 MB │ 10.8 MB │ 1.38 MB │ 8.04 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘
Req/Bytes counts sampled once per second.
289k requests in 5.03s, 54 MB read
On master it also produces a significant amount of warnings:
(node:235900) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
(node:235900) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
Update as of 2021/3/29 bisect from head a9cdeed:
- requestTimeout df08d52 80k -> 76k
- SafeArrayIterator 0b6d307 72k -> 67k
- align with stream.Writable e2f5bb7 67k -> 60k - revert at Revert "http: align with stream.Writable" #37963
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
Activity
mcollina commentedon Mar 26, 2021
cc @ronag
Linkgoron commentedon Mar 27, 2021
I think that the warning messages originated here: #36816
mcollina commentedon Mar 27, 2021
I think so as well.
ronag commentedon Mar 27, 2021
I will take a look as soon as I can
mcollina commentedon Mar 27, 2021
I'm looking into it as well!
ronag commentedon Mar 27, 2021
I will have time tonight. Please keep me posted if you find anything.
mcollina commentedon Mar 27, 2021
A couple of notes:
#36816 is the cause of the warnings and likely memory leak.
Going to the parent commit has a minor performance benefit:
The majority performance regression is present in v15 as well, so it's unrelated.
mcollina commentedon Mar 27, 2021
Apparently the majority of the regression happened in the v15 cycle.
v15.0.0: 77k req/sec (median)
v15.11.0: 67k req/sec (median)
ronag commentedon Mar 27, 2021
I will sort this.
ronag commentedon Mar 27, 2021
Are you bisecting?
ronag commentedon Mar 27, 2021
@mcollina: Any idea how to repro without using autocannon?
I tried:
mcollina commentedon Mar 27, 2021
I've done a
nvm"rough" bisect just narrow down a bit my scope of action.I'm doing a
git bisectas we speak, it just takes a lot of time as it spans several V8 versions.mcollina commentedon Mar 27, 2021
I think you need to use
netto send a manual request with http pipelining.35 remaining items
ronag commentedon Apr 2, 2021
@mcollina excellent work!
jasnell commentedon Apr 2, 2021
I've got the fix already identified, I'm just not writing any code today so I will do that first thing Monday morning and have the PR open soon after
ronag commentedon Apr 2, 2021
Do these things not show up when running a cpu profile? Seems a bit unfortunate that we need to git bisect to identify new or old performance bottlenecks?
mcollina commentedon Apr 2, 2021
They show up. However git bisecting is actually simpler because you do not have to code hypothetical fixes.
The hrtime showed up. It's far down from the main bottleneck, but it was a key difference on an hot path.
jasnell commentedon Apr 2, 2021
And I did run perf tests on this one change. I just think some of the other issues were masking the perf hit one the hrtime change making it far less obvious. Fortunately, it's a quick fix
http: optimize debug function correctly
mcollina commentedon Apr 15, 2021
Here is another one: #38245.
I have one more coming :).
mcollina commentedon Apr 15, 2021
#38246 include my last findings.
mcollina commentedon Apr 20, 2021
With the latest PRs having landed, the HTTP throughput of the upcoming v16 is on par with the one of the latest v14. I think this is a milestone and I'll celebrate to close this issue and possibly open a fresh one with other optimizations that we might want to do here.