I want C example for Multithreaded zmq client, I am already using Multithreaded server, but I have requirements to make each client send requests from multithreads not from a single thread.
I had a look at:
http://zguide.zeromq.org/c:asyncsrv
https://github.com/booksbyus/zguide/blob/master/examples/C/
but I didn't see client example that uses multithreads of ZMQ_DEALER socket talking to Multithreaded server ( a ZMQ_ROUTER socket )
So I am looking for DEALER and ROUTER pattern. I want the client ( the DEALER ) to be multithreaded:
- if I follow same analogy of multi-threaded server example, I need a proxy that binds multiple dealers threads, correct?
or
- is using a
pthread_createenough?
Currently my client is similar to hello world C:
zctx_t ctx = zctx_new ();
void *client = zsocket_new (ctx, ZMQ_REQ);
assert (client);
zsocket_connect (client, config.SERVER_ENDPOINT);
// SKIPPED: I get the data (hm->body.p) to be send through zmq...
// We send a request, then we work to get a reply
zstr_sendf(client, "%.*s", (int) hm->body.len,hm->body.p);
char *reply = zstr_recv (client);
if ( reply ) {
zsys_info ("server replied (%s)", reply);
free (reply);
}
Please help me make my C client to be a Multithreaded zmq client.
Update 1 (More details):
- I have a 3rd party application (let's call it
3pa) that I need to integrate with. The3pasends on average ~ 4HTTP POSTrequests per second ( each request's size ~ 60 KB ) to an HTTP Listener ( I am using mongoose ). 3paONLY sends a nextHTTP POSTafter it receives a"HTTP/1.1 200 OK\r\n""reply" OR after a timeout for the sent request. So3paseems to be single threaded.- In case I am not able to respond with
200 OKquickly, the3pawill keep queuing in Memory, until it crashes. - When I receive a request from
3pa, I need to send it over a 3G-mobile-packet network, to the backend server., using ZMQ. Due to the 3G-mobile-packet network latency and bandwidth, each request requires about 1-3 seconds to be sent, and about 1-3 seconds for a ZMQ replaynew ZFrame("OK")to be initiated, transported and delivered (received on the3paside).
So, if we make the elementary calculus, 3pa queue capacity will be filled up so fast due to the 3G-mobile-packet network performance.

Context( number_of_IO_threads )instance, where some additional low level hacks allow one to map some sockets for being handled with a given CPU/core affinity mapping. That makes sense for an advancedzmqdata-pumps' performance tuning. Could you translate your multithreading requirements into a plain english specification of must-have + nice-to-have properties? - user3666197