[zeromq-dev] Need help in creating multiple publisher and subscribers

Chuck Remes lists at chuckremes.com
Wed Aug 22 15:01:42 CEST 2012

On Aug 22, 2012, at 2:17 AM, girish kumar wrote:

> Hi All,
> We have started recently working on zero MQ. We could able to run the sample applications successfully. 
> We have two problems, which we are facing issues in getting answers.
> 1. We have a scenario where there are multiple publishers(threads) and multiple subscribers(threads). We are not able to understand a model in zero MQ, that works for this scenario. 
>   - As zero MQ sockets are not thread safe, can we make zero MQ sockets threadsafe by applying explicit locks?.

Each publisher thread should have its own socket. Each subscriber thread should also have its own socket. Create a single context and share it amongst all of your threads and create the sockets when the thread spins up. The library uses lockfree algos internally so if you decide to share a single pub/sub socket amongst several threads, the lock contention in your application code will kill performance. Let the library do the hard work since it is already optimized for this purpose.

> 2. Another problem is we are running some performance tests for best results. We would like to know the highest possible numbers(latency and throughput) achieved with zero MQ.

Use the tests in the perf/ subdirectory on the hardware you will be using. Latency and throughput are extremely sensitive to CPU speeds, bus speeds, network speeds and other hardware characteristics. Any numbers that I could quote you would be specific to my environment and therefore useless to you.


More information about the zeromq-dev mailing list