2个单向相同的gRPC调用会打开2个HTTP/2连接,还是它们会重复使用单个连接?

huangapple go评论56阅读模式
英文:

Will 2 unidirectional identical gRPC calls open 2 HTTP/2 connections or will they reuse a single connection?

问题

在我的聊天应用程序中(Nest.js + gRPC 微服务),我需要尽可能快地发送请求(用于创建消息),并担心重新打开连接(如果有的话)可能会花费太多时间和资源。

我尝试搜索文档,但没有找到明确的答案。每次我进行单向调用时,连接会重新打开吗?

英文:

In my chat app (Nest.js + gRPC microservices) I need to send requests (to create messages) as fast as possible and I worry that reopening the connection (if it is the case) can take too much time and resources.

I tried searching the docs but didn't find any clear answer. Will the connection reopen each time I make a unidirectional call?

答案1

得分: 1

HTTP/2支持多路复用,允许在单个连接上同时发送和接收多个请求和响应。这意味着即使它们几乎同时启动,也可以在同一HTTP/2连接上同时执行多个gRPC调用。

但是,需要注意行为可能会根据具体的gRPC库实现和配置而有所不同。某些库可能具有连接池机制或其他优化连接使用的策略。此外,服务器可能会限制单个连接上的并发流数量,如果达到限制,可能会导致打开其他连接。

英文:

HTTP/2 supports multiplexing, which allows multiple requests and responses to be sent and received over a single connection concurrently. This means that multiple gRPC calls can be performed over the same HTTP/2 connection simultaneously, even if they are initiated almost simultaneously.

Though, it's essential to note that the behavior may vary based on the specific gRPC library implementation and configurations. Some libraries might have connection pooling mechanisms or other strategies to optimize connection usage. Additionally, the server may limit the number of concurrent streams on a single connection, which could result in opening additional connections if the limit is reached.

huangapple
  • 本文由 发表于 2023年7月20日 22:31:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730948.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定