如何测试HTTP Keepalive是否真正起作用
我知道 HTTP keep-alive 在 HTTP 1.1 中默认处于启用状态,但我想找到一种方法来确认它确实有效。
有谁知道从网络浏览器进行测试的简单方法(例如如何理解wireshark)。我知道我需要通过同一 TCP 连接查找多个 HTTP 请求,但我不知道如何在wireshark 或任何其他方式中确认这一点。
谢谢!
I know HTTP keep-alive is on by default in HTTP 1.1 but I want to find a way to confirm that it is actually working.
Does anyone know of a simple way to test from a web browser (EG how to make sense of wireshark). I know I need to look for multiple HTTP requests over the same TCP connection but I don't know how to confirm that in wireshark or any other way.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 Ron Garrity 在 ServerFault 上所说的,您可以使用 Curl 像这样:
如果 keep-alive 正在工作,它会输出这两行:
如果 keep-alive 不起作用,那么它只会输出这一行:
As Ron Garrity said on ServerFault, you can use Curl like this:
And it outputs these two lines if keep-alive is working:
And if keep-alive is not working, then it just outputs this line:
如果您使用的是 Windows Vista 或更高版本,则可以使用资源管理器。 “网络”选项卡将列出所有打开的 TCP 连接及其启动的进程。打开带有一个选项卡的浏览器,浏览到您的页面并进行测试。
If you're on Windows Vista or later, you can use Resource Manager. The Network tab will list all open TCP connections and the process they were started by. Open a browser with one tab, browse to your page, and test.
curl
相同的 URL。如果输出包含
重新使用现有连接
,则 HTTP 保持活动功能正在运行。例如,ab
进行测试。但某些 HTTP 服务器可能不会返回Connection: keep-alive
标头,即使它们已经打开 keep-alive 功能(例如 uwsgi)。在这种情况下,ab
不会发送保持活动请求。这使得ab
只能对 HTTP keep-alive 进行“积极”检测。如果结果显示
则 HTTP keep-alive 已启用。
curl
the same URL multiple times.If the output contains
Re-using existing connection
, then the HTTP keep-alive feature is working. For example,ab
. But some HTTP servers might not return theConnection: keep-alive
header even when they've already turned on keep-alive feature, such as uwsgi. In such cases,ab
does NOT send keep-alive requests. That makesab
can only do "positive" detection on HTTP keep-alive.If the result shows
Then the HTTP keep-alive is enabled.
首先,尝试在 Wireshark 中捕获目标网站的流量,并使用以下过滤器将其限制为您需要的流量:
然后在浏览器中加载页面或通过您拥有的任何工具获取该页面。如果目标网页自行刷新或刷新其中的值之一,请将其保持打开状态,直到其中至少发生一项更改。
现在您已经有了足够的数据,您可以停止 Wireshark 中的捕获过程。
您应该看到几十条记录,它们的协议应该是 TCP 或 HTTP。为了快速简单的检查,您不需要 TCP 记录。因此,让我们通过应用另一个过滤器来删除它们。窗口顶部有一个“过滤器”字段。在那里输入 http,wireshark 将隐藏除具有 HTTP 协议的记录之外的所有记录。
现在选择一条记录并查看下一级详细信息,您可以在所有记录下方的第二个框中找到这些详细信息。为了确保您看到的是正确的位置,第一行以“Frame XYZ”开头。第四行以“传输控制协议”开头。查找“SRC Port”和“DST Port:”后面的端口号。根据记录,其中一个数字属于网络服务器(通常为 80),另一个显示您终端的端口号。
现在检查几个不同的 GET 记录。要了解请求是否是 GET 记录,请检查信息列。如果您端的端口号被多次使用,则所有这些请求都是通过 HTTP keepalive 发出的。
请记住,即使网络服务器支持 keepalive,大多数浏览器也会打开多个连接。因此,不要通过仅找到一个不同的端口来结束您的评估。
First, try to capture the traffic to the target website in Wireshark and limit it to what you need with a filter like:
Then load the page in a browser or fetch it by any tool you have. If the target web page refreshes itself or one of the values in it, leave it open until you have at least one change in it.
Now you have enough data and you can stop capturing procedure in Wireshark.
You should see dozens of records and their protocol should be TCP or HTTP. For the purpose of your quick simple check, you will not need TCP records. So, lets remove them by applying another filter. In top of the window there is a "filter" field. Type http there, and wireshark will hide all records but those which have a HTTP protocol.
Now select a record and look at the next level of details, which you can find in the 2nd box bellow all records. Just to be sure you are looking at the right place, the first line there starts with "Frame XYZ". The fourth line starts with "Transmission Control Protocol". Look for the port numbers after "SRC Port" and "DST Port:". Depending on the record, one of these numbers belongs to the webserver (typically 80) and the other one shows port number in your end.
Now check a couple of different GET records. To know if the request is a GET record, check the Info column. If the port numbers in your end are used several times, all those requests were made through HTTP keepalive.
Remember that most browsers will open multiple connections, even if the webserver supports keepalive. So, DO NOT conclude your evaluation by finding just one different port.