我们正在使用 Redis 消息总线并使用 channel 处理消息。但是如果我们的应用程序部署在多个实例中,那么请求和响应将传递给所有实例。为了避免这种情况,以下哪种方法更好?
- 为应用程序的每个实例创建一个 channel
- 为每个用户创建一个 channel
任何建议将不胜感激
最佳答案
此处的限制因素是同一 channel 的订阅者数量。 channel 的数量可能很大。所以你可以相应地选择粒度。在这里阅读更多内容:
https://groups.google.com/forum/#!topic/redis-db/R09u__3Jzfk
All the complexity on the end is on the PUBLISH command, that performs
an amount of work that is proportional to:
a) The number of clients receiving the message.
b) The number of clients subscribed to a pattern, even if they'll not
match the message.
This means that if you have N clients subscribed to 100000 different
channels, everything will be super fast.
If you have instead 10000 clients subscribed to the same channel,
PUBLISH commands against this channel will be slow, and take maybe a
few milliseconds (not sure about the actual time taken). Since we have
to send the same message to everybody.
关于redis - 在redis消息总线中为每个用户创建一个 channel 是一个好习惯吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54804050/