NGINX SSL Performance
NGINX SSL Performance
Performance
This paper investigates the performance of NGINX’s SSL termination under a range of traffic
types and ciphers. It seeks to establish a correlation between OpenSSL benchmarks and NGINX
performance, to enable users to rapidly estimate the capacity of selected hardware or virtual
machines.
Summary of Results
A single virtualized Intel core can typically perform up to 350 full 2048-bit SSL handshake
operations per second, using modern cryptographic ciphers. This equates to several hundred
new users of your service per second per core.
NGINX’s SSL performance scales with the number of cores available on the host server, until
other limits (typically bandwidth) are met, so an 8-core virtual machine could accept traffic from
over 1,000 new users per second and still have resources to spare.
Older, less compute-intensive ciphers can give significantly better performance in some
benchmarks, but the benefits are outweighed by the security improvements of modern SSL and
TLS ciphers.
An SSL connection will begin with an authentication step, where the server presents an
identifying ‘public certificate’ and the client verifies the server owns the corresponding RSA
private key.
In this step, the client encrypts some random data using the server’s public key (in the public
certificate) and the server then decrypts it using the private key. Both parties must agree on the
value of the client’s random data for the SSL handshake to proceed successfully.
What has changed? Until recently, 1024-bit RSA private keys were common, but industry
standards have now fully migrated to 2048-bit keys. In general, operations using 2048-bit keys
are 5 times slower than 1024-bit keys.
The client and server then need to negotiate a shared master secret that is used to derive the
encryption key for the SSL connection. The results of the RSA operation used in the
authentication step can be used to generate the shared secret, or an additional key-exchange
step can be used.
What has changed? Many published benchmarks select an SSL cipher that uses the RSA
operation in the authentication step to generate the shared secret. However, RSA-encrypted
session keys can be decrypted if the RSA key is compromised in the future.
Modern SSL implementations favor ‘Perfect Forward Secrecy’ methods1. This involves an
additional step in the SSL handshake where the server generates an ephemeral (temporary) key
pair for the connection. A shared secret is negotiated securely using this ephemeral key, and the
ephemeral key is then destroyed. However, improved security comes at the cost of greater
computation on behalf of the server, and a corresponding performance impact.
1
http://vincent.bernat.im/en/blog/2011-ssl-perfect-forward-secrecy.html
Once the shared secret is determined, both parties must negotiate a stream or block cipher (to
encrypt the data) and signing method (to generate message authentication codes) for data
transmission. The shared secret is used to derive the encryption and signing keys.
What has changed? The RC4 bulk cipher is now regarded as weak and now the slower AES128
cipher is preferred. MD5 and SHA-1 signing methods have now been replaced with SHA-256 or
other more secure but more expensive signing methods.
The expensive authentication and key negotiation operations in an SSL handshake do not need
be performed for every HTTP request. Clients are extremely efficient at using single HTTPS
connections for multiple GETs and reusing SSL session credentials across multiple SSL
connections.
The number of RSA operations per second that a server can perform provides an upper limit on
the number of new clients per second, not a limit on the number of individual requests per
second the server can perform.
Summary
It is very difficult to compare SSL performance benchmarks from different sources or vendors
without knowing the precise details of the SSL ciphers used. In this study, we will consider two
cipher combinations:
It’s even more difficult to infer real-world performance from benchmark results. The aim of this
study is to help you make some good judgements, but it’s no substitute for evaluating
performance on your own hardware, with your own content, applications and users.
2
https://www.ssllabs.com/ssltest/
Network throughput was measured using ab (apachebench) to transfer large files from client to
server using HTTP. 111 MBs application-layer throughput is consistent with a 1 GbE network, and
this should be regarded as the peak possible application network performance.
Cryptographic speed tests were taken using openssl speed. This is an easy-to-run process, and
this study investigates the correlations between openssl speed results and the benchmark
results:
• RSA operations per second measured using openssl speed rsa (signatures per
second with 2048-bit keys).
• RC4 throughput measured using openssl speed rc4 (bulk encryption with 1024-byte
block size).
• AES throughput measured using openssl speed aes, (128-bit key, 1024-byte block
sizes).
OpenSSL speed results are multiplied by the number of cores in the server to get total server
capacity.
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 TLS_RSA_WITH_RC4_128_SHA
3000.0
Requests
per
Second
2500.0
2000.0
1
core
1500.0
2
cores
1000.0
4
cores
500.0
8
cores
0.0
0
1k
10k
100k
1m
0
1k
10k
100k
1m
File
size
(bytes)
File
size
(bytes)
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 TLS_RSA_WITH_RC4_128_SHA
120.0
100.0
Bandwidth
(MBs)
80.0
1
core
60.0
2
cores
40.0
4
cores
20.0
8
cores
0.0
0
1k
10k
100k
1m
0
1k
10k
100k
1m
File
size
(bytes)
File
size
(bytes)
For small requests, where the performance is dominated by the handshake, the additional
ECDHA key exchange step reduces the performance of the ECDHA-RSA cipher to approximately
85% the performance of the simple RSA cipher.
For larger requests, where the performance is dominated by the bulk cipher, the AES-based
ciphers are approximately 35% the performance of the RC4 ciphers. Where performance is
dominated by available bandwidth, both ciphers are then limited by network bandwidth.
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
2500
Requests
per
Second
2000
0k
1500
1k
1000
10k
500
100k
1m
0
0
1000
2000
3000
4000
5000
RSA
speed
test
*
cores
The strongest correlation for Requests per Second for small files is against the RSA speed test:
… giving a rough approximation that requests per second for small files is between 50% and 60%
of the RSA speed, tailing off for more powerful machines where other factors (e.g. interrupt
handing) begin to affect performance.
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
140
Throughtput
(MB/second)
120
100
0
80
1k
60
10k
40
100k
20
1m
0
0
500
1000
1500
2000
AES
speed
test
*
cores
Determining a correlation between bandwidth and AES speed is more challenging because the
test network was only 1GbE-capable (approx. 111MB/s effective throughput), and because bulk
ciphers such as AES are relatively efficient; the performance of the cipher does not have a
significant bearing on the performance of the system.
The ‘sweet spot’ is clearly on low-powered machines (where bandwidth limits cannot be met),
with very large files (where the very-expensive RSA operation has less effect). We saw a peak
throughput of 25% the theoretical AES speed, but overall throughput limits quickly dominated.
Because the cipher is relatively lightweight, there is not a strong correlation between theoretical
speed and actual speed.
TLS_RSA_WITH_RC4_128_SHA
120
Throughput
(MB/second)
100
80 0
60 1k
40
10k
100k
20
1m
0
0
1000
2000
3000
4000
5000
RC4
speed
test
*
cores
Note that even the low-powered machines in the test quickly saturated the 1 GbE network when
using the RC4 bulk cipher.
AES-NI is a set of instructions on modern Intel processors that accelerates the encryption speed
of the AES algorithm.
The virtual machines used in these tests were not AES-NI-capable. Informal reports indicate that
AES-NI is between 4-8x the performance of AES, so one would expect that the performance
difference against RC4 would be significantly reduced or eliminated.
Conclusions
NGINX software can handle large volumes of SSL traffic on a modern 8-core or beyond server.
Scalability is very cost-effective; NGINX leverages general-purpose physical or virtual hardware
and SSL connections-per-second scales linearly with the number of cores, up to other limitations
in the hardware or operating system.
A single virtualized Intel core can typically perform up to 350 full 2048-bit SSL handshake
operations per second; this equates to several hundred new users of your service per second per
core. NGINX’s SSL performance scales with the number of cores available on the host server, until
other limits (typically bandwidth) are met, so an 8-core virtual machine could accept traffic from
over 1,000 new users per second and still have resources to spare.
For other hardware, you can use openssl tests to determine approximately what the SSL capacity
could be.
Specialized hardware devices exist that can perform many thousands of RSA operations per
second. You should consider whether the cost of these devices (acquisition, support, upgrades)
is merited given the traffic levels you need to terminate, and the corresponding cost of an NGINX-
based solution.