HTTP:流水线,保持活动和服务器发送事件之间的关系是什么? [英] HTTP: what are the relations between pipelining, keep-alive and Server Sent Events?

查看:144
本文介绍了HTTP:流水线,保持活动和服务器发送事件之间的关系是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解什么是HTTP流水线和HTTP保持活动连接,并尝试在这两个主题和服务器发送事件技术之间建立连接。

I am trying to understand what are the HTTP pipelining and HTTP keep-alive connections, and trying to establish a connection between these two topics and Server Sent events technology.

据我了解,当建立的一次TCP连接用于逐个发送多个HTTP请求时,
HTTP保持连接是HTTP 1.1使用TCP的默认方式。
HTTP流水线是客户端向服务器发送请求的功能,而使用相同的TCP连接尚未收到对先前请求的响应,通常不会在浏览器中用作默认方式。

As far as I understand, HTTP keep-alive connection is the default in HTTP 1.1 way of using TCP when the established once TCP connection is used for sending several HTTP requests one by one. HTTP pipelining is the capability of client to send requests to server while responses to previous requests were not yet received using the same TCP connection, generally not used as a default way in browsers.

我的问题:

1)是否可以使用一个TCP连接一个接一个地向服务器发送多个请求 - 客户如何区分响应?我猜客户端正在使用FIFO顺序发送服务器的响应?

1) if it is possible to send several requests to server one after one using one TCP connection - how the client can distinguish between the responses? I guess client is using FIFO order of sending responses by server?

2)为什么非幂等请求(如POST请求)不应该被流水线化(根据维基百科)?

2) Why non-idempotent requests such as POST requests shouldn't be pipelined (according to wikipedia)?

3)Web服务器的局限性是什么:可能的开放TCP连接数量是多少?如果是,那么如果某些客户端保持keep-alive连接,则其他客户端无法建立连接,这可能会导致问题,对吧?

3) What about the limitations of the web-server: is the number of possible open TCP connections limited? If yes, then if some number of clients hold keep-alive connections others cannot establish connections, and this can result in a problem, right?

4)服务器发送事件正在使用保持活动连接,但据我所知,SSE没有使用流水线技术。相反,他们设法处理对一个请求的多个响应,或者他们只是在下一个事件响应到达时发送另一个请求。哪个猜测是正确的?

4) Server Sent Events are using the keep-alive connection but, as far as I understand, SSE are not using pipelining. Instead they manage to process several responses to one request, or may be they just send another request when the next response with event arrived. Which guess is correct?

5)一个TCP连接是指一个套接字?一个套接字意味着一个TCP连接?关闭/打开套接字意味着关闭/打开TCP连接?

5) One TCP connection means one socket? One socket means one TCP connection? Closing/opening socket means closing/opening TCP connection?

推荐答案


  1. 是,FIFO。 TCP / IP保证按顺序交付数据,因此响应不能以不同的顺序到达(如果服务器/代理有错误并且发送响应的顺序错误,那么您就完全搞砸了)。

  1. Yes, FIFO. TCP/IP guarantees delivering data in-order, so responses can't arrive in a different order (if the server/proxy is buggy and sends responses in wrong order then you're totally screwed).

我不记得每个HTTP规范的任何原因。可能只是谨慎,因为某些代理/服务器中的流水线实现很差。

I don't recall any reason per HTTP spec. It may be just caution, because pipelining is poorly implemented in some proxies/servers.

HTTP规范表明每台服务器有2个连接,浏览器已经确定为6-8每台服务器的连接,但没有固定的限制。连接耗尽对于Apache来说是一个真正的问题,对于高负载情况,建议在Apache中禁用KeepAlive并使用可以廉价地为客户端提供Keep-Alive功能的代理(例如HAProxy)。

代理的好处是一个代理可以将连接分发到多个服务器(有助于扩展),或者可以修改流量(例如gzip压缩所有内容,即使服务器端软件没有)。

HTTP spec suggests 2 connections per server, browsers have settled on 6-8 connections per server, but there is no fixed limit. Running out of connections is a real problem for Apache, and for high-load situations it's recommended to disable KeepAlive in Apache and use a proxy (e.g. HAProxy) that can cheaply provide Keep-Alive functionality to clients.
The benefit of a proxy is that one proxy can distribute connections to several servers (helps scaling), or can modify the traffic (e.g. gzip compress everything even if server-side-software didn't).

SSE不依赖于Keep-Alive。它没有使用多个响应。这是一个永远下载的单一响应,因此流水线操作或保持活动与SSE无关。在发送SSE响应时,TCP / IP连接不能再返回任何响应。

只要连接打开,SSE就会使服务器保持忙碌(这对每个用户来说都是典型的)。这就是为什么最好将SSE与Node.js / Tornado一起使用,它可以处理数十万个连接,而不是一次为几个连接设计的PHP / Apache。

SSE doesn't rely on Keep-Alive. It's not using multiple responses. It's a single response that takes forever to "download", so pipelining or keep-alive are irrelevant for SSE. The TCP/IP connection cannot return any more responses while SSE response is being sent.
SSE will keep the server busy as long as the connection is open (so typicall all the time for every user). That's why it's best to use SSE with Node.js/Tornado that can handle hundreds of thousands connections rather than PHP/Apache that is designed for few connections at a time.

套接字是TCP / IP连接的编程接口。通常是的,一个套接字是一个连接。

Sockets are programming interface for TCP/IP connections. Generally yes, one socket is one connection.

这篇关于HTTP:流水线,保持活动和服务器发送事件之间的关系是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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