保持活动标题说明 [英] Keep-alive header clarification

查看:17
本文介绍了保持活动标题说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求建立一个网站,其中一位联合开发人员告诉我,我需要包含 keep-alive 标头.

好吧,我读了很多关于它的内容,但我仍然有问题.

将返回保持活动标题

解决方案

此信息保存在哪里(此连接在计算机 A 和服务器 F 之间")?

TCP 连接由源 IP 和端口以及目标 IP 和端口识别.您的操作系统、所有中间会话感知设备和服务器的操作系统将通过此识别连接.

HTTP 与请求-响应一起工作:客户端连接到服务器,执行请求并获得响应.如果没有 keep-alive,与 HTTP 服务器的连接会在每次响应后关闭.使用 HTTP keep-alive,您可以保持底层 TCP 连接处于打开状态,直到满足某些条件.

这允许在单个 TCP 连接上实现多个请求-响应对,从而消除了一些 TCP 相对较慢的连接启动.

<块引用>

当 IIS (F) 发送 keep-alive 头(或用户发送 keep-alive)时,是否意味着 (E,C,B) 保存了连接

没有.路由器不需要记住会话.事实上,属于同一个 TCP 会话的多个 TCP 数据包不需要都经过同一个路由器——这是由 TCP 管理的.路由器只是选择最佳 IP 路径并转发数据包.Keep-alive 仅适用于客户端、服务器和任何其他中间会话感知设备.

<块引用>

这仅适用于我的会话?

<块引用>

这是否意味着没有其他人可以使用该连接

这就是 TCP 连接的意图: 这是一个只为这两方设计的端到端连接.

<块引用>

如果是这样-是否意味着keep alive-header-减少重叠连接用户的数量?

定义重叠连接".请参阅 HTTP 持久连接了解一些优点和缺点,例如:

  • 降低 CPU 和内存使用率(因为同时打开的连接更少).
  • 启用请求和响应的 HTTP 管道.
  • 减少网络拥塞(减少 TCP 连接).
  • 减少后续请求的延迟(无握手).
<块引用>

如果是这样,连接会保存多久?(换句话说,如果我设置保持活动-保持"直到什么时候?)

典型的保持活动响应如下所示:

Keep-Alive: timeout=15, max=100

参见 超文本传输​​协议 (HTTP) Keep-例如,Alive 标头(HTTP/2 的草案,其中对 keep-alive 标头的解释比 26162086):

  • 主机将 timeout 参数的值设置为主机允许空闲连接在关闭之前保持打开的时间.如果主机没有发送或接收数据,则连接处于空闲状态.

  • max 参数表示客户端将发出的最大请求数,或者服务器将允许在持久连接上发出的最大请求数.一旦发送了指定数量的请求和响应,包含该参数的主机就可以关闭连接.

但是,服务器可以在任意时间或任意数量的请求后关闭连接(只要它返回对当前请求的响应).具体如何实现取决于您的 HTTP 服务器.

I was asked to build a site , and one of the co-developer told me That I would need to include the keep-alive header.

Well I read alot about it and still I have questions.

msdn ->

The open connection improves performance when a client makes multiple requests for Web page content, because the server can return the content for each request more quickly. Otherwise, the server has to open a new connection for every request

Looking at

  • When The IIS (F) sends keep alive header (or user sends keep-alive) , does it mean that (E,C,B) save a connection which is only for my session ?
  • Where does this info is kept ( "this connection belongs to "Royi") ?
  • Does it mean that no one else can use that connection
  • If so - does it mean that keep alive-header - reduce the number of overlapped connection users ?
  • if so , for how long does the connection is saved to me ? (in other words , if I set keep alive- "keep" till when?)

p.s. for those who interested :

clicking this sample page will return keep alive header

解决方案

Where is this info kept ("this connection is between computer A and server F")?

A TCP connection is recognized by source IP and port and destination IP and port. Your OS, all intermediate session-aware devices and the server's OS will recognize the connection by this.

HTTP works with request-response: client connects to server, performs a request and gets a response. Without keep-alive, the connection to an HTTP server is closed after each response. With HTTP keep-alive you keep the underlying TCP connection open until certain criteria are met.

This allows for multiple request-response pairs over a single TCP connection, eliminating some of TCP's relatively slow connection startup.

When The IIS (F) sends keep alive header (or user sends keep-alive) , does it mean that (E,C,B) save a connection

No. Routers don't need to remember sessions. In fact, multiple TCP packets belonging to same TCP session need not all go through same routers - that is for TCP to manage. Routers just choose the best IP path and forward packets. Keep-alive is only for client, server and any other intermediate session-aware devices.

which is only for my session ?

Does it mean that no one else can use that connection

That is the intention of TCP connections: it is an end-to-end connection intended for only those two parties.

If so - does it mean that keep alive-header - reduce the number of overlapped connection users ?

Define "overlapped connections". See HTTP persistent connection for some advantages and disadvantages, such as:

  • Lower CPU and memory usage (because fewer connections are open simultaneously).
  • Enables HTTP pipelining of requests and responses.
  • Reduced network congestion (fewer TCP connections).
  • Reduced latency in subsequent requests (no handshaking).

if so , for how long does the connection is saved to me ? (in other words , if I set keep alive- "keep" till when?)

An typical keep-alive response looks like this:

Keep-Alive: timeout=15, max=100

See Hypertext Transfer Protocol (HTTP) Keep-Alive Header for example (a draft for HTTP/2 where the keep-alive header is explained in greater detail than both 2616 and 2086):

  • A host sets the value of the timeout parameter to the time that the host will allows an idle connection to remain open before it is closed. A connection is idle if no data is sent or received by a host.

  • The max parameter indicates the maximum number of requests that a client will make, or that a server will allow to be made on the persistent connection. Once the specified number of requests and responses have been sent, the host that included the parameter could close the connection.

However, the server is free to close the connection after an arbitrary time or number of requests (just as long as it returns the response to the current request). How this is implemented depends on your HTTP server.

这篇关于保持活动标题说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆