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

其他回答

考虑到SSL需要一个非sll HTTP不需要的额外加密步骤,这几乎肯定是正确的。

一个更重要的性能差异是HTTPS会话在用户连接时保持打开。一个HTTP“会话”只持续一个项目请求。

如果你正在运行一个有大量并发用户的网站,预计会购买大量内存。

HTTP和HTTPS性能比较

与传统的HTTP相比,我总是将HTTPS与较慢的页面加载时间联系起来。作为一个网页开发人员,网页性能对我来说很重要,任何会降低我网页性能的东西都是禁忌。

为了理解所涉及的性能影响,下面的图向您提供了使用HTTPS对资源发出请求时的基本概念。

从上图中可以看出,与使用普通HTTP相比,使用HTTPS需要执行一些额外的步骤。当您使用HTTPS发出请求时,需要进行握手以验证请求的真实性。与HTTP请求相比,这个握手是一个额外的步骤,不幸的是会引起一些开销。

为了理解性能影响并亲自查看性能影响是否显著,我使用这个站点作为测试平台。我访问了webpagetest.org,并使用可视化比较工具来比较使用HTTPS和HTTP加载的站点。

正如您可以从这里看到的测试视频结果使用HTTPS确实对我的页面加载时间有影响,但差异是可以忽略不计的,我只注意到300毫秒的差异。需要注意的是,这些时间取决于许多因素,如计算机性能、连接速度、服务器负载以及与服务器的距离。

您的站点可能有所不同,因此彻底测试您的站点并检查切换到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秒

对此有一个非常简单的答案:分析您的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.