在同一客户端和服务器之间使用多个GRPC流(而不是C#中的一个),是否存在性能劣势?
想象一下,您想将多个Protobuf消息类型从服务器流式传输到同一客户端。设计流服务有不同的方法,例如,假设我想流式传输3种不同类型的消息,例如通知,状态和事件:
选项1-每种类型的流
rpc StreamingService {
rpc NotificationStream(NotificationStreamingRequest) returns (stream Notification);
rpc StateStream(StateStreamingRequest) returns (stream State);
rpc EventStream(EventStreamingRequest) returns (stream Event);
}
选项2-所有类型的流,
rpc StreamingService {
rpc Stream(Request) returns (stream Message);
}
message Message {
oneof type {
Notification notification = 1;
State state = 2;
Event event = 3;
}
}
而选项1 将为代码中的服务提供更清洁的实现,选项2 似乎是通信系统的更好选择。但是,除了额外的标头和拖车元数据以外,选项1 中是否有实际开销,由于多个流,现在多次发送了多次?
在 performance最佳实践官方GRPC网站的最佳实践仅提及使用流rpcs的RPC用于长寿命数据流以避免连续的RPC启动,并为每个高负载区域创建一个单独的通道,如果每个流都有高度,则实际上会偏爱选项1 加载,因为那时每个流都可以使用自己的GRPC通道。
绩效最佳实践使用GRPC 来自MS Docs,它确实反对选项1 ,除了服务器上并发流的最大限制。
是否真的与选项1 并在同一客户服务器连接中使用多个流有关吗?在拥有多个流时,技术层面上是否有任何真正的性能障碍?
Imagine you want to stream multiple protobuf message types from a server to the same client. There are different ways to design the streaming service, e.g. assuming I want to stream 3 different types of messages, for example notifications, states and events:
Option 1 - One stream per type
rpc StreamingService {
rpc NotificationStream(NotificationStreamingRequest) returns (stream Notification);
rpc StateStream(StateStreamingRequest) returns (stream State);
rpc EventStream(EventStreamingRequest) returns (stream Event);
}
Option 2 - One stream for all types
rpc StreamingService {
rpc Stream(Request) returns (stream Message);
}
message Message {
oneof type {
Notification notification = 1;
State state = 2;
Event event = 3;
}
}
While Option 1 would offer a cleaner implementation for the services in the code, Option 2 seems like the better option for communication systems. But is there any actual overhead in Option 1 other than the additional header and trailer metadata that now gets send multiple times due to multiple streams?
In the Performance Best Practices of the official gRPC website it is only mentioned to use streaming RPCs for long-lived data flow to avoid continuous RPC initiation, and to create a separate channel for each area of high load, which would actually favor Option 1 if each stream has a high load, because then each stream could use its own gRPC channel.
There is also nothing mentioned in the Performance best practices with gRPC from the MS Docs that really speaks against Option 1, other than the maximum limit of concurrent streams on servers.
Does anything really speak against Option 1 and using multiple streams in the same client-server connection? Is there any real performance disadvantadge on a technical level when having multiple streams?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论