简体   繁体   English

我们是否还需要一个连接池来支持HTTP2的微服务?

[英]Do we still need a connection pool for microservices talking HTTP2?

As HTTP2 supports multiplexing, do we need still a pool of connections for microservice communication? 由于HTTP2支持多路复用,我们还需要一个用于微服务通信的连接池吗? If yes, what are the benefits of having such a pool? 如果是,拥有这样一个游泳池有什么好处?

Example: Service A => Service B 示例:服务A =>服务B.

Both the above services have only one instance available. 上述两种服务都只有一个实例可用。

Multiple connections may help overcome OS buffer size limitation for each Connection(Socket)? 多个连接可能有助于克服每个连接(套接字)的OS缓冲区大小限制? What else? 还有什么?

Yes, you still need connection pool in a client contacting a microservice. 是的,您仍需要联系微服务的客户端中的连接池。

First, in general it's the server that controls the amount of multiplexing. 首先,通常它是控制多路复用量的服务器。 A particular microservice server may decide that it cannot allow beyond a very small multiplexing. 特定的微服务服务器可以决定它不允许超出非常小的多路复用。
If a client wants to use that microservice with a higher load, it needs to be prepared to open multiple connections and this is where the connection pool comes handy. 如果客户端想要使用具有更高负载的微服务,则需要准备打开多个连接,这就是连接池的便利之处。 This is also useful to handle load spikes. 这对处理负载峰值也很有用。

Second, HTTP/2 has flow control and that may severely limit the data throughput on a single connection. 其次,HTTP / 2具有流量控制,可能严重限制单个连接上的数据吞吐量。 If the flow control window are small (the default defined by the HTTP/2 specification is 65535 bytes, which is typically very small for microservices) then client and server will spend a considerable amount of time exchanging WINDOW_UPDATE frames to enlarge the flow control windows, and this is detrimental to throughput. 如果流控制窗口很小(HTTP / 2规范定义的默认值为65535字节,对于微服务通常非常小),则客户端和服务器将花费大量时间来交换WINDOW_UPDATE帧以扩大流控制窗口,这对吞吐量有害。
To overcome this, you either need more connections (and again a client should be prepared for that), or you need larger flow control windows. 要解决这个问题,您需要更多连接(并且客户端应该为此做好准备),或者您需要更大的流量控制窗口。

Third, in case of large HTTP/2 flow control windows, you may hit TCP congestion (and this is different from socket buffer size) because the consumer is slower than the producer. 第三,在大型HTTP / 2流控制窗口的情况下,您可能会遇到TCP拥塞(这与套接字缓冲区大小不同),因为消费者比生产者慢。 It may be a slow server for a client upload (REST request with a large payload), or a slow client for a server download (REST response with a large payload). 它可能是客户端上载的慢速服务器(具有大负载的REST请求),也可能是服务器下载的慢客户端(具有大负载的REST响应)。
Again to overcome TCP congestion the solution is to open multiple connections. 再次为了克服TCP拥塞,解决方案是打开多个连接。

Comparing HTTP/1.1 with HTTP/2 for the microservice use case, it's typical that the HTTP/1.1 connection pools are way larger (eg 10x-50x) than HTTP/2 connection pools, but you still want connection pools in HTTP/2 for the reasons above. 对于微服务用例,将HTTP / 1.1与HTTP / 2进行比较,通常HTTP / 1.1连接池比HTTP / 2连接池更大(例如10x-50x),但您仍然希望HTTP / 2中的连接池为原因如上。

[Disclaimer I'm the HTTP/2 implementer in Jetty ]. [免责声明我是Jetty的HTTP / 2实现者]。
We had an initial implementation where the Jetty HttpClient was using the HTTP/2 transport with an hardcoded single connection per domain because that's what HTTP/2 preached for browsers. 我们有一个初始实现,其中Jetty HttpClient使用HTTP / 2传输与每个域的硬编码单连接,因为这是HTTP / 2为浏览器提供的。
When exposed to real world use cases - especially microservices - we quickly realized how bad of an idea that was, and switched back to use connection pooling for HTTP/2 (like HttpClient always did for HTTP/1.1). 当暴露给真实世界的用例 - 尤其是微服务 - 时,我们很快意识到这个想法有多糟糕,并且切换回使用HTTP / 2的连接池(就像HttpClient总是为HTTP / 1.1做的那样)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们真的需要微服务中的事件采购和CQRS吗? - Do we really need Event Sourcing and CQRS in microservices? 我需要微服务中的事务队列吗? - Do I need transactional queues in Microservices? HTTP2:内部服务 API 是否应该使用 http2 - HTTP2: Should inner service apis use http2 无法建立 HTTP/2 连接,因为服务器未完成 HTTP/2 握手 gRPC 微服务 .net 核心 - An HTTP/2 connection could not be established because the server did not complete the HTTP/2 handshake gRPC Microservices .net core 什么是微服务,与 MVC 有什么联系 - What is Microservices and is there a connection with MVC 为什么我们需要像 2PC 或 SAGA 这样的模式来执行微服务之间的顺序事务? - Why we need patterns like 2PC or SAGA to perform sequential transactions between microservices? 需要澄清微服务 - need clarification on microservices 什么时候不应该使用微服务? - When we should not to use microservices? 如果有“N”个微服务,那么我们是否必须在 Zuul Api Gateway 中手动配置它们呢? - What if there are 'N' numbers of microservices then do we have to configure them all manually in Zuul Api Gateway? 微服务架构中的HTTP vs Thrift - HTTP vs Thrift in microservices architecture
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM