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


当前回答

TLS快吗?是的。

看:https://www.youtube.com/watch?v=0EB7zh_7UE4 阅读:https://istlsfastyet.com/

有许多项目旨在模糊界限,使HTTPS一样快。比如SPDY和mod-spdy。

其他回答

目前最上面的答案并不完全正确。

正如其他人在这里指出的,https需要握手,因此需要更多的TCP/IP往返。

在WAN环境中,延迟通常成为限制因素,而不是服务器上增加的CPU使用量。

请记住,从欧洲到美国的延迟大约是200毫秒(往返时间)。

您可以使用HTTPWatch轻松地测量这一点(对于单个用户情况)。

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产生了重大影响。您可能应该对站点进行概要分析(正如其他人建议的那样)以确保这一点,但我怀疑性能差异不会很明显。

HTTPS有加密/解密的开销,所以它总是会稍微慢一点。SSL终止是非常消耗CPU的。如果您有卸载SSL的设备,则延迟的差异可能几乎不明显,这取决于服务器所处的负载。

这里似乎有一个令人讨厌的边缘情况:Ajax胜过拥塞的wifi。

Ajax通常意味着KeepAlive在20秒后超时。然而,wifi意味着(理想的快速)ajax连接必须进行多次往返。更糟糕的是,wifi经常丢包,并且有TCP重传。在这种情况下,HTTPS执行得非常非常糟糕!

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秒