如何扩展 gRPC 发布/订阅聊天服务?
我正在研究如何与GRPC进行聊天服务。我注意到大多数示例将所有订户的连接存储在列表数据结构中。当聊天室收到一条新消息时,服务器将循环浏览该列表并发送新消息。
将订阅者存储在源代码的变量订户。
我的问题是,当订户编号长大并将所有订户存储在哈希图中似乎是一个坏主意,因为这会花费太多的内存?我试图将这些连接存储在redis中,但是可能不可能由于连接无法序列化。
我的想法是当我在Kubernetes中部署多个POD实例时。每个聊天服务都变得独立。当订户分发在不同的服务器上时,我该如何正确获取订户?
I'm studying how to make a chat service with gRPC. I notice that most of the examples store all the subscriber's connections into a List data structure. When the chatroom got a new message, the server will loop through that List and send new messages.
Stores subscribers in source code's variable subscribers.
My question is that when the subscriber number grows up and storing all the subscribers in the HashMap seems like a bad idea because that will cost too much memory? I have tried to store those connections in Redis but it might be impossible due to the connection is not serializable.
My Idea is when I deploy multiple pod instances in Kubernetes. Each chat service becomes independent. How could I get the subscribers correctly when they are distributed on different servers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我思考的几个方面:
Here are a couple of aspects that I'm thinking: