nats-server: Very high CPU usage during initial TLS setup

Defects

Versions of gnatsd and affected client libraries used:

server 1.0.2 latest go client

OS/Container environment:

centos 7 on ec2 t2.medium

Steps or code to reproduce the issue:

create 16 000 TLS connections as quick as you can

Expected result:

I know TLS is quite heavy and initial setup is costly but perhaps somewhere something can be tuned, this seems excessively slow

Once the initial TLS handshakes are done and connections are up CPU usage is back down to a good 2% no problem

Actual result:

NATS, for 90 seconds or so, using all available CPU on all cores

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (24 by maintainers)

Most upvoted comments

Yes. When no cipher is configured, in Go 1.8, the NATS Server will use these as the default:

tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,

Below 1.8, it uses:

tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,

He is using 1.0.2 but unfortunately, this was built with Go 1.7.6, which does not have the CHACHA ones. Any chance you can build from master with Go 1.8+ to try?

Which cipher is being used? You could run server with -D and run only one of the client to see what cipher is being negotiated between the two. You may want to make sure that you use a faster cipher (CHACHA ones). Are you using on top of that authorization with bcrypt or token?

If we can improve we will, but still, it is expected that if you do create that many connections at once, there will be burden in the CPU. I would recommend adding some random delay in the creation of all those connections.