Optimizing HTTPS performance

TLS has exactly one performance problem: it is not used widely enough.

Everything else can be optimized.

CPU & latency costs

The process of establishing and communicating over an encrypted channel introduces additional computational costs. First, there is the asymmetric (public key) encryption used during the TLS handshake. Then, once a shared secret is established, symmetric encryption takes over.

# upgrade to latest
$> openssl version
OpenSSL 1.0.2f  28 Jan 2016

# run benchmarks
$> openssl speed sha
$> openssl speed ecdh

Good news is, modern hardware has made great improvements to help minimize these costs, and what once may have required additional hardware can now be done efficiently by the CPU.

On our production frontend machines, SSL/TLS accounts for less than 1% of the CPU load, less than 10 KB of memory per connection and less than 2% of network overhead. Many people believe that SSL/TLS takes a lot of CPU time and we hope the preceding numbers will help to dispel that.
– Adam Langley, Google “Overclocking SSL”

We have deployed TLS at a large scale using both hardware and software load balancers. We have found that modern software-based TLS implementations running on commodity CPUs are fast enough to handle heavy HTTPS traffic load without needing to resort to dedicated cryptographic hardware.
– Doug Beaver, Facebook “HTTP2 Expression of Interest”

Elliptic Curve Diffie-Hellman (ECDHE) is only a little more expensive than RSA for an equivalent security level… In practical deployment, we found that enabling and prioritizing ECDHE cipher suites actually caused negligible increase in CPU usage. HTTP keepalives and session resumption mean that most requests do not require a full handshake, so handshake operations do not dominate our CPU usage. We find 75% of Twitter’s client requests are sent over connections established using ECDHE. The remaining 25% consists mostly of older clients that don’t yet support the ECDHE cipher suites.
– Jacob Hoffman-Andrews, Twitter “Forward Secrecy at Twitter”

《Optimizing HTTPS performance》

Server performance

TLS exposes many different knobs and new config flags on every server. Our goal here is not to provide an exhaustive list (consult server docs for that), but to highlight status of important performance-oriented features: resumption, stapling, false start (requires ALPN and forward secrecy), and support for the HTTP/2 protocol.

Your favorite server missing, or found an error? Open a pull request![2]

CDN & PaaS performance

Using a CDN allows us to terminate the connection close to the user, which can significantly reduce the cost of TCP and TLS handshake – see early termination. For best results you should be using a CDN to serve both static and dynamic content.

Session identifiersSession ticketsOCSP staplingDynamic record sizingALPNForward secrecyHTTP/2
Akamaiyesyesyesconfigurable (static)yesyesyes[3]
CloudFlareyesyesyesdynamicyesyeshttp/2[4]
Incapsulayesyesnonoyesyesyes[5]
AWS ELByesyesnononoyes[6]no
AWS CloudFrontnoyesyesnoyesyesno
EdgeCastnoyesyesnonoyesno
Fastlyyesyesyesnonoyesno
Google App Engineyesyesnodynamicyesyeshttp/2
Herokuyesyesnononoyesno
Instart Logicyesyesnoconfigurable (static)yesyesspdy/3.1
Limelightyesyesnononoyesno
MaxCDNyesyesyes[7]noyesyesspdy/3.1
KeyCDNyesyesyes[8]configurable (static)yesyeshttp/2[9]
QUANTILyesyesnononoyesno
ChinaNetCenteryesyesnononoyesno

Your favorite CDN or PaaS provider missing, or found an error? Open a pull request![10]

FAQ

What about benchmarks?

Quality of implementation matters — no argument there — and you should do your due diligence. That said, you need to test on your own hardware and with realistic traffic patterns to get an accurate picture of what works best for your specific workload. Don’t trust outdated benchmarks, update your OpenSSL libraries, update your server, and run the tests.

TLS operational costs are still higher, right?

Not necessarily. Once you enable and optimize your TLS stack you’re also well on your way to deploying HTTP/2. Unlike HTTP/1.1, HTTP/2 requires only a single connection per origin, which means fewer sockets, memory buffers, TLS handshakes, and so on. As a result, it may well be the case that you will be able to handle more users with fewer resources[11].

TLS still adds an extra RTT; can we fix that?

One possible route is to leverage TCP Fast Open, which would allow us to send the ClientHello within the TCP SYN packet — that would cut another RTT. In the meantime, both TLS 1.3[12] and QUIC are experimenting with “zero-RTT” handshake mechanisms. See QUIC crypto doc[13] and this GDL episode[14] for a general introduction to QUIC.

Which ciphersuite should I be using?

Mozilla maintains a wiki page with a recommended ciphersuite list and server configuration tips.

If TLS False Start is enabled, do I need resumption?

Both resumption and TLS False Start eliminate an extra roundtrip from the TLS handshake. However, resumption also allows you to skip the asymmetric handshake crypto by reusing parameters from a previous session — this saves CPU cycles. In other words, yes you need both.

I run a multi-server deployment. Any tips?

Ensure you have a shared session cache to get a good cache hit rate on resumed sessions across different servers. Also, ensure you expire and rotate your sessions and session ticket keys in a secure manner, especially when forward secrecy is enabled[15].

What about certificate costs?

You can get free certificates for any use from Let’s Encrypt[16]. If you need EV verification, then you will have to pay a bit extra. Use your favorite search engine to look for and evaluate the available options. The security and integrity of your visitors’ data is worth every penny!

What about Elliptic Curve Cryptography (ECC) certificates?

ECC certificates offer stronger security and smaller certificates[17] – e.g. a 256-bit ECC key is equivalent to a 3072-bit RSA key. However, many clients do not support ECDSA[18], which means that the server should support both RSA and ECDSA, and some popular servers do not support dual certificate deployments. Consult the documentation of your server to see if RSA+ECDSA is a supported option.

What about CRIME and BREACH attacks?

CRIME[19] is an attack against compression at the TLS layer. All modern user agents disable TLS compression, but it is still recommended that you disable TLS compression on your server. BREACH[20], on the other hand, is an attack against compression on top of TLS (e.g. HTTP compression) and must be mitigated both at the server and application levels – read more[21].

How do I migrate my existing site to HTTPS?

Checkout the HTTPS Everywhere presentation[22] (slides[23]) from Google I/O to learn the best practices and the steps to safely migrate your existing content to HTTPS.

Why do we need HTTPS everywhere?

Every unencrypted HTTP request reveals information about user’s behavior. Today, there is no such thing as insensitive web traffic – read more[24].

Where can I learn more about TLS performance?

    原文作者:HTTP
    原文地址: https://juejin.im/entry/56b0368179bc440054a30ad5
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞