保持活跃的标题澄清 [英] Keep-alive header clarification

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

问题描述

我被要求建立一个网站,其中一位合作开发者告诉我,我需要包含keep-alive标题。



我读了很多,我仍有疑问。



将返回keep alive header

解决方案


此信息保存在何处(此连接介于计算机 A 和服务器 F ) ?


源IP和端口以及目标IP和端口识别TCP连接。您的操作系统,所有中间会话感知设备和服务器的操作系统将识别连接这就是。



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仅适用于客户端,服务器和任何其他中间会话感知设备。


仅适用于我的会话?



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


这就是< a href =http://en.wikipedia.org/wiki/End-to-end_principle#The_canonical_case:_TCP.2FIP\"rel =noreferrer> TCP连接的意图:它是一个结束 - 仅适用于那两方的终端连接。


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


定义重叠连接。有关一些优点和缺点,请参见 HTTP持久连接,例如:




  • 降低CPU和内存使用量(因为同时打开的连接数较少)。

  • 启用请求和响应的HTTP流水线。

  • 减少网络拥塞(减少TCP连接)。

  • 减少后续请求的延迟(无握手)。




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


典型的保持活动响应看起来像这样:

  Keep-Alive:timeout = 15,max = 100 

参见超文本传输​​协议(HTTP)保持活动标头(HTTP / 2的草案,其中保持活动标头比 2616 2086 ):




  • 主机将 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天全站免登陆