c++ - ZeroMq PUB/SUB pattern not working properly -


my requirements:

  1. high throughput, atleast 5000 messages per second
  2. order of delivery not important
  3. publisher, obvious, should not wait response , should not care if subscriber listening or not

background:

i creating new thread every message because if dont, messages generation part out-speed sending thread , messages lost, thread each message seems right approach

problem:

the problem somehow threads started send out zmq message not being terminated (not exiting/finishing). there seems problem in following line:

s_send(*client, request.str());

because if remove threads terminate fine, line causing problems, first guess thread waiting response, zmq_pub wait response?

here code:

void *sendhello(void *threadid) {     long tid;     tid = (long) threadid;     //cout << "hello world! thread id, " << tid << endl;     std::stringstream request;     //writing hex request sent server     request << tid;     s_send(*client, request.str());     pthread_exit(null); }  int main() {     int sequence = 0;      int num_threads = 1000;     while (1) {         pthread_t threads[num_threads];         int rc;         int i;         (i = 0; < num_threads; i++) {             cout << "main() : creating thread, " << << endl;             rc = pthread_create(&threads[i], null, sendhello, (void *) i);         pthread_detach(threads[i]);         sched_yield();              if (rc) {                 cout << "error:unable create thread," << rc << endl;                 exit(-1);             }         }         //usleep(1000);         sleep(1);     }     pthread_exit(null);     //delete client;     return 0; } 

my question:

do need tweak zmq sockets pub doesnt wait reply doing wrong?

edit:

adding client definition:

static zmq::socket_t * s_client_socket(zmq::context_t & context) {     std::cout << "i: connecting server." << std::endl;     zmq::socket_t * client = new zmq::socket_t(context, zmq_sub);     client->connect("tcp://localhost:5555");      // configure socket not wait @ close time     int linger = 0;     client->setsockopt(zmq_linger, &linger, sizeof (linger));     return client; }  zmq::context_t context(1); zmq::socket_t * client = s_client_socket(context); 

but zmq_pub wait response?

no, case if socket wasn't pub socket , hit high-water mark, isn't case. messages sent?


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -