zmq vs redis for pub-sub pattern

后端 未结 4 1268
一生所求
一生所求 2020-12-23 21:43

redis supports pub-sub
zmq also supports pub-sub via a message broker

What would be the architectural pros\\cons for choosing between them?

4条回答
  •  遥遥无期
    2020-12-23 22:09

    I have been researching this myself as I needed to decide whether to use Redis pubsub or ZMQ pubsub for communication layer for distributed systems. I think Redis and ZMQ differ in terms of how application is setup.

    1. ZMQ pubsub innately connect directly i.e. no middle man.
      You can create middle-man like instance such as forwarder device

    2. For Redis pubsub, both subscriber and publisher need to connect to Redis.

    The lack of middle-man in ZMQ means subscriber needs to somehow know to connect to publisher to get the message. In my system where application spawn publishers that needs to send info to subscribers, there is no way of doing that without having forwarder device that subscribers connect to before my application starts.

    Latency matters in my system as I want remote boxes to do things as fast as it can.

    Zmq (direct pubsub)
    avg: 0.000235867897669
    max: 0.0337719917297
    min: 0.000141143798828
    
    Zmq (w/ forwarder)
    Avg: 0.00237249334653
    max: 0.00536799430847
    min: 0.000249862670898
    
    Redis (8gb ram)
    avg: 0.000687216520309
    max: 0.0483138561249
    min: 0.000313997268677
    
    Redis (32gb ram)
    avg: 0.000272458394368
    max: 0.00277805328369
    min: 0.000216960906982
    
    • if your application is on the subscriber side where there is publisher daemon that you want to get info from, then i would go for ZMQ because you can directly connect to publisher.
    • if your application is on publisher side, then i would go to Redis pubsub because subscribers are already connected to Redis listening.

提交回复
热议问题