为什么GRPC使用HTTP2而不是纯TCP?

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

Why GRPC uses HTTP2 instead of pure TCP?

问题

建立基于TCP的RPC协议比使用HTTP2更高效,HTTP2主要设计用于Web服务并具有额外的开销。在应用层协议上再建立另一个应用层协议的意义是什么?为什么gRPC不直接在TCP上构建其协议?

英文:

To my knowledge, building an RPC protocol based on TCP is more efficient than using HTTP2, which is designed primarily for web services and has additional overhead. What is the meaning of building another application layer protocol over an application layer protocol? Why does not GRPC build its protocol directly over TCP?

答案1

得分: 3

这取决于您如何衡量效率 为什么GRPC使用HTTP2而不是纯TCP?

如果您愿意采用原始的TCP,并且将在其之上添加额外功能的分层视为零开发成本,那么TCP可能更有效率。但它们实际上并不是真正的零成本,因为您需要开发和测试它们。

另一方面,HTTP/2 提供了一些额外的功能(真正的零开发成本),这些功能对位于其之上的协议可能很有用。

例如,它提供了二进制帧、头部压缩、在单个TCP会话上并行进行请求/响应组的多路复用以及在服务器可以确定客户端需求而无需额外请求的情况下进行服务器推送。

我知道 gRPC 使用头部压缩,因为我曾经看到它的 hpack 日志输出。我不确定它是否使用其他功能,但出于性能考虑,我认为它们可能非常有用。

英文:

Well, that depends on how you measure efficiency 为什么GRPC使用HTTP2而不是纯TCP?

If you're willing to take raw TCP and consider the layering of extra facilities on top of it to be zero development cost then, yes, TCP would probably be more efficient. But they're not really zero cost since you have to develop and test them.

HTTP/2, on the other hand, provides some extra facilities (at true zero development cost) which may be useful to protocols sitting on top of it.

For example, it provides binary framing, header compression, multiplexing (in parallel) request/response groups on a single TCP session, and server push in cases where the server can ascertain client needs without extra requests coming in.

I know for a fact that gRPC uses header compression since I've seen the debug output with its hpack logging. I'm not sure if it uses the other things but, for performance, I suspect they'd be quite handy.

huangapple
  • 本文由 发表于 2023年6月1日 02:58:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376534.html
匿名

发表评论

匿名网友

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

确定