Skip to content

High cpu usage for outbound ssl requests after upgrading from v16.15.0 to v18.1.0 #43128

Closed as not planned
@str1ke

Description

@str1ke

Version

v18.1.0

Platform

Linux 5.17.4-arch1-1 #1 SMP PREEMPT Wed, 20 Apr 2022 18:29:28 +0000 x86_64 GNU/Linux

Subsystem

crypto

What steps will reproduce the bug?

I have observed this problem in few http clients: axios, got. But looks like a problem is in node.js itself.

  1. Create a basic http server which produces outbound ssl requests and returns in response result of outbound request. Here is a sample
consthttp=require("http");consthttps=require("https");constport=3000;consthandler=(req,res)=>{https.get("https://server.local",(response)=>{letbody="";response.on('data',chunk=>{body+=chunk;});response.on("end",()=>{res.statusCode=response.statusCode;res.setHeader('Content-Type','text/plain');res.end(body);});});};constserver=http.createServer(handler);server.listen(port);
  1. Start to produce load to server. I'm using hey
hey -z 1m -c 10 -disable-keepalive "http://client.local:3000" 
  1. Observe in CPU profiler for node.js server constantly increasing cpu usage for SecureContext.init(). It starts from ~50% and going up to 80%. Amount of requests processed by server, which sends outbound https requests is constantly decreasing.

How often does it reproduce? Is there a required condition?

Always reproduces if present outbound ssl requests and node version 18.1.0

What is the expected behavior?

Constant CPU usage, amount of processed requests is at the same level during time. In node.js v16.15.0 same code in CPU profiler have SecureContext.init() with usage of 5-8%. And during load there is no performance degradation.

What do you see instead?

CPU usage is keeping increasing during time, SecureContext.init() starts from ~50% cpu time in profiler and keep growing during time to 80-85%. Amount of requests processed by server is constantly decreasing.

Additional information

v18.1.0
Benchmark result - 186 req/s
node --perf output - https://pastebin.com/wyHPXfMH
cpu profile screenshot
cpu_profile_v18 1 0

v16.15.0
Benchmark result - 1184 req/s
node --perf output - https://pastebin.com/0L0Z01iq
cpu profile screenshot
cpu_profile_v16 15 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      close