可以通过负载均衡器启用保持活动状态吗?

发布于 2024-12-17 12:55:31 字数 317 浏览 4 评论 0原文

我正在尝试使用 Google 的 Page Speed API 来优化我的 Web 应用程序,该 API 强调了我的 HTTP 响应标头中缺少“Keep-alive”作为主要的页面速度弱点。

在与我的后端开发人员和系统管理员交谈时,他们告诉我,在网站上使用 Keep-alive 是不可能的,因为我们使用负载均衡器。

我想知道,这准确吗?是否有支持 Keep-alive 的负载均衡器?

我觉得奇怪的是,如果无法与负载均衡器一起使用,Page Speed API 会抱怨 Keep-alive,因为我想象有相当多的应用程序和大型站点使用负载均衡器。

谢谢!

I'm trying to optimize my web application using Google's Page Speed API which has highlighted the absence of "Keep-alive" in my HTTP response headers as a major page speed weakness.

In talking with my back-end devs and sys admins, they've told me that using Keep-alive on the site is impossible because we use a load balancer.

I'm wondering, is this accurate? Are there load balancers that support Keep-alive?

It seems strange to me that the Page Speed API would complain about Keep-alive if it were impossible to use with load balancers because I would imagine a fair amount of applications and large sites use load balancers.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

背叛残局 2024-12-24 12:55:31

我不知道你有什么类型的负载平衡器......但我不认为它会阻止使用保持活动连接。

负载均衡器将处理与其中一台后端服务器的每个传入连接。现在,对于每个对象,浏览器需要建立一个新连接才能获取该对象(例如所有小图像)。建立和关闭 TCP 连接需要一些时间。这就是 Google Page Speed 建议打开 keep-alive 的原因。另一种选择是将所有小图像放入一个大图像中,并使用 css sprites 将其部分显示在页面上的不同位置。

回到负载均衡器。如果您有网络负载均衡器,它应该可以毫无问题地工作 - 它只会将传入的 TCP 连接重定向到后端服务器之一。如果您有 HTTP 负载均衡器,它将接受连接,读取请求,将请求发送到后端服务器,等待它应答并将答案发送回浏览器。如果启用保持活动状态,负载均衡器应转发通过同一连接收到的下一个请求。

对于动态页面,您不需要保持活动状态。 Keep-alive 主要对静态内容(js、图像、css)有用,因为每个 html 页面通常有超过 10 个静态对象。因此,我建议继续通过负载均衡器提供 html 服务,并通过不同的主机名(static.example.com)提供静态内容。

I don't know what type of load-balancers do you have... but I don't think that it would prevent the use of keep-alive connections.

The load balancer will handle each incoming connection to one of the backend servers. Now for each object the browser needs to make a new connection just to fetch that object (for example all small images). Establishing and closing TCP connections takes some time. This is why the Google Page Speed suggests to have keep-alive turned on. Another option is put all your small images into one big image and use css sprites to display part of it on different places on your page.

But back to the load balancer. If you have network load balancer, it should work without any questions - it will just redirect incoming TCP connection to one of the backend servers. If you have HTTP load-balancer, it will accept the connection, read the request, send the request to backend server, wait for it to answer and send the answer back to the browser. If you enable keep-alive, the load balancer should forward the next request it receives over the same connection.

For dynamic pages you don't need keep-alive. Keep-alive is mainly useful for static content (js, images, css) as for each one html page you have usually more than 10 static objects. So I would suggest to continue serving html trough that load-balancer and serve static content over different hostname (static.example.com).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文