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


当前回答

除了到目前为止提到的所有内容,请记住,出于安全原因,一些(所有?)web浏览器不会将通过HTTPS获得的缓存内容存储在本地硬盘上。这意味着,从用户的角度看,在浏览器重启后,含有大量静态内容的页面加载速度会变慢,而从服务器的角度看,通过HTTPS请求静态内容的量将比通过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秒

有一种方法可以衡量这一点。来自apache的jmeter工具将测量吞吐量。如果您在受控环境中使用jmeter对您的服务进行了大量采样,无论是否使用SSL,都应该得到相对成本的准确比较。我对你的结果很感兴趣。

对此有一个非常简单的答案:分析您的web服务器的性能,看看在您的特定情况下性能损失是什么。有几个工具可以比较HTTP和HTTPS服务器的性能(我想到了JMeter和Visual Studio),而且它们很容易使用。

没有人能给你一个有意义的答案没有一些关于你的网站的性质,硬件,软件和网络配置的信息。

正如其他人所说,由于加密,会有一定程度的开销,但它高度依赖于:

硬件 服务器软件 动态与静态内容的比例 客户端到服务器的距离 典型会话长度 等等(我个人的最爱) 客户端的缓存行为

根据我的经验,动态内容较多的服务器受HTTPS的影响较小,因为与内容生成时间相比,加密所花费的时间(ssl开销)微不足道。

大量服务于相当小的静态页面集(这些页面可以很容易地缓存在内存中)的服务器会遭受更高的开销(在一个案例中,吞吐量在“内部网”上受到了影响)。

编辑:有一点已经被其他几个人提出,SSL握手是HTTPS的主要成本。这是正确的,这就是为什么“典型会话长度”和“客户端的缓存行为”很重要。

很多非常短的会议意味着握手时间将压倒其他任何表现因素。较长的会话将意味着在会话开始时产生握手成本,但后续请求的开销将相对较低。

Client caching can be done at several steps, anywhere from a large-scale proxy server down to the individual browser cache. Generally HTTPS content will not be cached in a shared cache (though a few proxy servers can exploit a man-in-the-middle type behavior to achieve this). Many browsers cache HTTPS content for the current session and often times across sessions. The impact the not-caching or less caching means clients will retrieve the same content more frequently. This results in more requests and bandwidth to service the same number of users.

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

除了到目前为止提到的所有内容,请记住,出于安全原因,一些(所有?)web浏览器不会将通过HTTPS获得的缓存内容存储在本地硬盘上。这意味着,从用户的角度看,在浏览器重启后,含有大量静态内容的页面加载速度会变慢,而从服务器的角度看,通过HTTPS请求静态内容的量将比通过HTTP请求的量要高。