gpt4 book ai didi

html - 如何配置 HAProxy 以处理服务器发送的事件?

转载 作者:太空狗 更新时间:2023-10-29 13:14:26 24 4
gpt4 key购买 nike

我正在尝试向发送服务器发送事件的现有应用程序添加端点。通常可能有大约 5 分钟没有事件。我希望将该端点配置为即使响应未在 ~1 分钟内完成也不会切断我的服务器,但如果服务器无法响应,所有其他端点将超时。

有没有简单的方法来支持 HAProxy 中的服务器发送事件?

最佳答案

以下是我对 HAProxy 和 SSE 的建议:您在 HAProxy 中有很多自定义超时选项,并且有 2 个有趣的选项供您使用。

timeout tunnel 指定隧道连接超时 - 用于 Websockets、SSE 或 CONNECT。绕过服务器和客户端超时。

timeout client 处理客户端失去连接的情况(网络丢失、在结束 session 的 ACK 之前消失等...)

在你的 haproxy.cfg 中,这是你应该做的,首先在你的 defaults 部分:

# Set the max time to wait for a connection attempt to a server to succeed
timeout connect 30s
# Set the max allowed time to wait for a complete HTTP request
timeout client 50s
# Set the maximum inactivity time on the server side
timeout server 50s

在那之前没什么特别的。

现在,仍然在 defaults 部分:

# handle the situation where a client suddenly disappears from the net
timeout client-fin 30s

接下来,跳转到您的 backend 定义并添加:

timeout tunnel 10h

我建议一个高值,10 小时似乎还可以。

您还应该避免使用默认的 http-keep-alive 选项,SSE 不使用它。相反,请使用 http-server-close

关于html - 如何配置 HAProxy 以处理服务器发送的事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21419859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com