http和https在性能上有什么主要的区别吗?我似乎记得读到过HTTPS的速度是HTTP的五分之一。这对当前的web服务器/浏览器有效吗?如果有,是否有相关白皮书支持?


当前回答

HTTPS requires an initial handshake which can be very slow. The actual amount of data transferred as part of the handshake isn't huge (under 5 kB typically), but for very small requests, this can be quite a bit of overhead. However, once the handshake is done, a very fast form of symmetric encryption is used, so the overhead there is minimal. Bottom line: making lots of short requests over HTTPS will be quite a bit slower than HTTP, but if you transfer a lot of data in a single request, the difference will be insignificant.

然而,keepalive是HTTP/1.1的默认行为,所以你会在同一个连接上进行一次握手,然后进行多次请求。这对HTTPS产生了重大影响。您可能应该对站点进行概要分析(正如其他人建议的那样)以确保这一点,但我怀疑性能差异不会很明显。

其他回答

因为我正在为我的项目调查同样的问题,我发现了这些幻灯片。年长但有趣:

http://www.cs.nyu.edu/artg/research/comparison/comparison_slides/sld001.htm

我可以告诉你(作为一个拨号用户),通过SSL访问同一个页面要比通过常规HTTP慢几倍…

Browsers can accept HTTP/1.1 protocol with either HTTP or HTTPS, yet browsers can only handle HTTP/2.0 protocol with HTTPS. The protocol differences from HTTP/1.1 to HTTP/2.0 make HTTP/2.0, on average, 4-5 times faster than HTTP/1.1. Also, of sites that implement HTTPS, most do so over the HTTP/2.0 protocol. Therefore, HTTPS is almost always going to be faster than HTTP simply due to the different protocol it generally uses. However, if HTTP over HTTP/1.1 is compared with HTTPS over HTTP/1.1, then HTTP is slightly faster, on average, than HTTPS.

以下是我使用Chrome(版本64)运行的一些比较:

HTTPS over HTTP/1.1:

0.47秒的平均页面加载时间 在HTTP/1.1上比HTTP慢0.05秒 比HTTP/2.0上的HTTPS慢0.37秒

HTTP over HTTP/1.1

0.42秒的平均页面加载时间 比HTTP/1.1上的HTTPS快0.05秒 比HTTP/2.0上的HTTPS慢0.32秒

HTTPS over HTTP/2.0

平均加载时间0.10秒 在HTTP/1.1上比HTTP快0.32秒 比HTTPS/1.1快0.37秒

HTTPS requires an initial handshake which can be very slow. The actual amount of data transferred as part of the handshake isn't huge (under 5 kB typically), but for very small requests, this can be quite a bit of overhead. However, once the handshake is done, a very fast form of symmetric encryption is used, so the overhead there is minimal. Bottom line: making lots of short requests over HTTPS will be quite a bit slower than HTTP, but if you transfer a lot of data in a single request, the difference will be insignificant.

然而,keepalive是HTTP/1.1的默认行为,所以你会在同一个连接上进行一次握手,然后进行多次请求。这对HTTPS产生了重大影响。您可能应该对站点进行概要分析(正如其他人建议的那样)以确保这一点,但我怀疑性能差异不会很明显。

这个问题没有一个单一的答案。

加密总是会消耗更多的CPU。在许多情况下,这可以卸载到专用的硬件上,成本将根据所选择的算法而变化。例如,3des比AES更贵。有些算法对加密者来说比解密者更昂贵。有些则有相反的代价。

比批量加密更昂贵的是握手成本。新的连接将消耗更多的CPU。这可以通过会话恢复来减少,代价是保留旧的会话秘密直到它们过期。这意味着来自客户端的小请求是最贵的。

对于跨互联网流量,您可能不会注意到数据速率的成本,因为可用带宽太低了。但您肯定会在繁忙的服务器上的CPU使用情况中注意到这一点。