I've got several server apps that use a shared ZMQ class I created. Occasionally when these servers process a request, they need to send a message to another ZMQ server. I'm fairly new to ZMQ so I wanted to make sure I understand this correctly.
The class that handles the server listener creates a zmq::context_t
and zmq::socket_t
, and binds the socket. This runs on a separate thread infinitely. When this server needs to send a message in another function ( completely torn-off from this ZMQ class ), would I need to generate a new context here and send the message, or should I somehow pass down the same context to this class ( on a different thread ), bind a new socket then go from there?
If the former, does it matter what number I use to initialize the new context, or is context( 1 )
fine? There's a part in the guide that says creating a second context is like having multiple instances of ZMQ, which I don't think really matters since its only being used to send a file then closing. But I'm probably wrong?
context
ought never be a "consumable/disposable", it has a lot of overhead associated with its instantiation. The number ofIOthreads
is another story -- more related with achieving a minimum latency, blocking-state robustness and data-pumping performance ( or performance-class based grouping ). SeeZMQ_AFFINITY
used for mapping of individual socket(s) onto respectiveIOthread
-#(s). High-performance + low-latency code simply has to tweak these internalities to the max.inproc://
transport-class is IO-less & may use an instance ofcontext( 0 )
it is a memory map. – Hesitate