0

I have some code which basically does this psudocode()

registerCamera(id) {
       createRedisPubChannel("Camera_"+id)
}

cameraDisconnect() {
        removeRedisSubChannel("Camera_"+id)
}

I then communicate with that camera through that channel and this allows me to have multiple engines.

I could also structure the code so that instead of creating a channel per camera. I could create one channel called "cameraComms" and make sure every message contains a camera id.

I wonder are there any performance advantages / disadvantages to either design pattern?

If it helps I can have up to 200+ cameras registered per process, and communication is across 3 different boxes running 3 instances of Redis.

Help/advice greatly appreciated.

Alan Hollis
  • 1,292
  • 3
  • 14
  • 29

1 Answers1

1

Pre-Requisite:

In performance perspective, no. of channels, no. of publishers and no. of subscribers doesn't matter but the frequency and amount of messages you deal with does matters.

For example,

1 publisher publishing 1000 messages at a time causes more overhead than 1000 publishers sending 1 message at a time.

Similarly 1 subscriber receiving 1000 messages will cause more overhead than 1000 subscribers receiving 1 message at a time.

More the subscribers subscribing to a same channel, more is the copy of the messages published, which is a overhead.

So the thumb Rule here is :

 1. Publisher do not flood messages at once.
 2. Subscriber must not be in a position to receive flooded messages at once.

To answer your question:

If your publisher is heavy you can use n channels for n camera. 1 publisher will publish in a channel and 1 subscriber will receive those messages. In this way you will end up with n channels, n publishers and n subscribers.

If your publisher is not heavy you can use a single channel where the publisher will send the camera ID and your single subscriber will consume the message and process.

Karthikeyan Gopall
  • 5,469
  • 2
  • 19
  • 35