您的位置:首页 > 理论基础 > 计算机网络

http-keepalive

2017-03-03 00:00 134 查看
HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using the same TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair – Wikipedia.

HTTP pipelining is a technique in which multiple HTTP requests are sent on a single TCP connection without waiting for the corresponding responses.[1] -Wikipedia

简单说就是连接复用,客户端和web服务器都要支持才行.下面用tomcat做个试验.

环境
1.使用ab测试

2.本地启动tomcat服务

3.wireshark查看tcp握手情况

预期目标:

多次请求只有一次tcp握手

tomcat 服务器参数配置

acceptCount="1" maxConnections="1" maxThreads="1" minSpareThreads="1" disableKeepAlivePercentage="100"

因为我们配置的工作线程已经backlog都是1那么disableKeepAlivePercentage这个参数必须给设置为100.具体参数说明及验证以后再写.

ab 测试 加上 -k参数,表明启用http keep-alive

结果



可以看到只有一次握手

对比试验

让服务器不支持 keepalive disableKeepAlivePercentage=0 (表明工作线程占比为超过0%关闭对keepalive支持). 或者去掉ab -k参数

结果:



每次请求都是一次完整的tcp握手/挥手过程
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  http Keepalived keep-alive