コード例 #1
0
ファイル: zmq.hpp プロジェクト: ATNF/askapsdp
        inline explicit context_t (int io_threads_, int max_sockets_ = 1024)
        {
            ptr = zmq_ctx_new ();
            if (ptr == NULL)
                throw error_t ();

            int rc = zmq_ctx_set (ptr, ZMQ_IO_THREADS, io_threads_);
            ZMQ_ASSERT (rc == 0);

            rc = zmq_ctx_set (ptr, ZMQ_MAX_SOCKETS, max_sockets_);
            ZMQ_ASSERT (rc == 0);
        }
コード例 #2
0
ファイル: test_ctx_options.cpp プロジェクト: roalz/libzmq
int main (void)
{
    setup_test_environment();
    int rc;
    
    //  Set up our context and sockets
    void *ctx = zmq_ctx_new ();
    assert (ctx);
    
    assert (zmq_ctx_get (ctx, ZMQ_MAX_SOCKETS) == ZMQ_MAX_SOCKETS_DFLT);
#if defined(ZMQ_USE_SELECT)
    assert (zmq_ctx_get (ctx, ZMQ_SOCKET_LIMIT) == FD_SETSIZE - 1);
#elif    defined(ZMQ_USE_POLL) || defined(ZMQ_USE_EPOLL)     \
      || defined(ZMQ_USE_DEVPOLL) || defined(ZMQ_USE_KQUEUE)
    assert (zmq_ctx_get (ctx, ZMQ_SOCKET_LIMIT) == 65535);
#endif
    assert (zmq_ctx_get (ctx, ZMQ_IO_THREADS) == ZMQ_IO_THREADS_DFLT);
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 0);
    assert (zmq_ctx_get (ctx, ZMQ_MSG_T_SIZE) == sizeof (zmq_msg_t));
    
    rc = zmq_ctx_set (ctx, ZMQ_IPV6, true);
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 1);
    
    void *router = zmq_socket (ctx, ZMQ_ROUTER);
    int value;
    size_t optsize = sizeof (int);
    rc = zmq_getsockopt (router, ZMQ_IPV6, &value, &optsize);
    assert (rc == 0);
    assert (value == 1);
    rc = zmq_getsockopt (router, ZMQ_LINGER, &value, &optsize);
    assert (rc == 0);
    assert (value == -1);
    rc = zmq_close (router);
    assert (rc == 0);
    
    rc = zmq_ctx_set (ctx, ZMQ_BLOCKY, false);
    assert (zmq_ctx_get (ctx, ZMQ_BLOCKY) == 0);
    router = zmq_socket (ctx, ZMQ_ROUTER);
    rc = zmq_getsockopt (router, ZMQ_LINGER, &value, &optsize);
    assert (rc == 0);
    assert (value == 0);
    rc = zmq_close (router);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);

    return 0;
}
コード例 #3
0
void test_reconnect_ivl_tcp_ipv6 ()
{
    if (is_ipv6_available ()) {
        zmq_ctx_set (get_test_context (), ZMQ_IPV6, 1);
        test_reconnect_ivl_tcp ("tcp://[::1]:*");
    }
}
コード例 #4
0
ファイル: test_many_sockets.cpp プロジェクト: ALeschev/tunel
void test_system_max ()
{
    // Keep allocating sockets until we run out of system resources
    const int no_of_sockets = 2 * 65536;
    void *ctx = zmq_ctx_new ();
    zmq_ctx_set (ctx, ZMQ_MAX_SOCKETS, no_of_sockets);
    std::vector <void*> sockets;

    while (true) {
        void *socket = zmq_socket (ctx, ZMQ_PAIR);
        if (!socket)
            break;
        sockets.push_back (socket);
    }
    assert ((int) sockets.size () < no_of_sockets);

    //  System is out of resources, further calls to zmq_socket should return NULL
    for (unsigned int i = 0; i < 10; ++i) {
        void *socket = zmq_socket (ctx, ZMQ_PAIR);
        assert (socket == NULL);
    }
    // Clean up.
    for (unsigned int i = 0; i < sockets.size (); ++i)
        zmq_close (sockets [i]);

    zmq_ctx_destroy (ctx);
}
コード例 #5
0
int main (void)
{
    setup_test_environment();
    int rc;

    //  Set up our context and sockets
    void *ctx = zmq_ctx_new ();
    assert (ctx);

    assert (zmq_ctx_get (ctx, ZMQ_MAX_SOCKETS) == ZMQ_MAX_SOCKETS_DFLT);
    assert (zmq_ctx_get (ctx, ZMQ_IO_THREADS) == ZMQ_IO_THREADS_DFLT);
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 0);

    rc = zmq_ctx_set (ctx, ZMQ_IPV6, true);
    assert (zmq_ctx_get (ctx, ZMQ_IPV6) == true);

    void *router = zmq_socket (ctx, ZMQ_ROUTER);
    int ipv6;
    size_t optsize = sizeof (int);
    rc = zmq_getsockopt (router, ZMQ_IPV6, &ipv6, &optsize);
    assert (rc == 0);
    assert (ipv6);

    rc = zmq_close (router);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);

    return 0;
}
コード例 #6
0
ファイル: frr_zmq.c プロジェクト: Azure/sonic-bcm-lkm
void frrzmq_init(void)
{
	if (frrzmq_initcount++ == 0) {
		frrzmq_context = zmq_ctx_new();
		zmq_ctx_set(frrzmq_context, ZMQ_IPV6, 1);
	}
}
コード例 #7
0
void test_reconnect_ivl_tcp_ipv6 ()
{
    if (is_ipv6_available ()) {
        zmq_ctx_set (get_test_context (), ZMQ_IPV6, 1);
        test_reconnect_ivl_tcp (bind_loopback_ipv6);
    }
}
コード例 #8
0
void test_shutdown_stress_tipc ()
{
    void *s1;
    void *s2;
    int i;
    int j;
    pthread_t threads[THREAD_COUNT];

    for (j = 0; j != 10; j++) {
        //  Check the shutdown with many parallel I/O threads.
        setup_test_context ();
        zmq_ctx_set (get_test_context (), ZMQ_IO_THREADS, 7);

        s1 = test_context_socket (ZMQ_PUB);

        TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (s1, "tipc://{5560,0,0}"));

        for (i = 0; i != THREAD_COUNT; i++) {
            s2 = zmq_socket (get_test_context (), ZMQ_SUB);
            TEST_ASSERT_SUCCESS_RAW_ERRNO (
              pthread_create (&threads[i], NULL, worker, s2));
        }

        for (i = 0; i != THREAD_COUNT; i++) {
            TEST_ASSERT_SUCCESS_RAW_ERRNO (pthread_join (threads[i], NULL));
        }

        test_context_socket_close (s1);

        teardown_test_context ();
    }
}
コード例 #9
0
ファイル: Context.cpp プロジェクト: kodjobaah/jzmq
JNIEXPORT jboolean JNICALL Java_org_zeromq_ZMQ_00024Context_setMaxSockets (JNIEnv * env, jobject obj, jint maxSockets)
{
    void *c = get_context (env, obj);
    if (! c)
        return JNI_FALSE;
    int result = zmq_ctx_set (c, ZMQ_MAX_SOCKETS, maxSockets);
    return result == 0;
}
コード例 #10
0
        inline explicit context_t (int io_threads_)
        {
            ptr = zmq_ctx_new ();
            if (ptr == NULL)
                throw error_t ();

            int rc = zmq_ctx_set (ptr, ZMQ_IO_THREADS, io_threads_);
            ZMQ_ASSERT (rc == 0);
        }
コード例 #11
0
ファイル: context.cpp プロジェクト: Fantasticer/zmqpp
void context::set(context_option const& option, int const& value)
{
	if (nullptr == _context) { throw invalid_instance("context is invalid"); }

	if (0 != zmq_ctx_set(_context, static_cast<int>(option), value))
	{
		throw zmq_internal_exception();
	}
}
コード例 #12
0
ファイル: zmq.cpp プロジェクト: gparmer/libzmq
void *zmq_init (int io_threads_)
{
    if (io_threads_ >= 0) {
        void *ctx = zmq_ctx_new ();
        zmq_ctx_set (ctx, ZMQ_IO_THREADS, io_threads_);
        return ctx;
    }
    errno = EINVAL;
    return NULL;   
}
コード例 #13
0
ファイル: ext_zmq.cpp プロジェクト: Orvid/php-zmq
void HHVM_METHOD(ZMQContext, setOpt, int64_t option, int64_t value) {
  auto ctx = Native::data<ZMQContext>(this_);

  if (option != ZMQ_MAX_SOCKETS) {
    throwExceptionClass(s_ZMQContextExceptionClass, "Unknown option key", PHP_ZMQ_INTERNAL_ERROR);
  }

  if (zmq_ctx_set(ctx->context->z_ctx, option, value) != 0) {
    throwExceptionClassZMQErr(s_ZMQContextExceptionClass, "Failed to set the option ZMQ::CTXOPT_MAX_SOCKETS value: {}", errno);
  }
}
コード例 #14
0
	Bool  HawkZmqManager::SetupZmqCtx(Int32 iThreads)
	{
		if (!m_pZmqCtx)
		{
			m_pZmqCtx = zmq_ctx_new();
			if (m_pZmqCtx)
			{
				zmq_ctx_set(m_pZmqCtx, ZMQ_IO_THREADS, iThreads);
			}
		}
		return m_pZmqCtx != 0;
	}
コード例 #15
0
bool ZeroMQContext::initContext()
{
   bool ok = true;

   // Create a new context
   if (ok) {
      context = zmq_ctx_new();
      if (context == nullptr)
         ok = false;
   }

   // Set context options
   if (ok && (threadCount != -1))  ok = (zmq_ctx_set(context, ZMQ_IO_THREADS,  threadCount) == 0);
   if (ok && (maxSockets  != -1))  ok = (zmq_ctx_set(context, ZMQ_MAX_SOCKETS, maxSockets)  == 0);
   if (ok && (enableIPV6  != -1))  ok = (zmq_ctx_set(context, ZMQ_IPV6,        enableIPV6)  == 0);

   // Indicate the context is ready... or not
   ready = ok;

   return ok;
}
コード例 #16
0
ファイル: zinfo.c プロジェクト: kmiku7/practice
int main(int argc, char** argv)
{

  int io_threads = 4;
  void* context = zmq_ctx_new();
  zmq_ctx_set(context, ZMQ_IO_THREADS, io_threads);
  printf("io thread num: %d\n", zmq_ctx_get(context, ZMQ_IO_THREADS));

  zmq_ctx_destroy(context);

  return 0;
}
コード例 #17
0
int main (void)
{
    setup_test_environment();
    void *s1;
    void *s2;
    int i;
    int j;
    int rc;
    void* threads [THREAD_COUNT];

    for (j = 0; j != 10; j++) {

        //  Check the shutdown with many parallel I/O threads.
        void *ctx = zmq_ctx_new ();
        assert (ctx);
        zmq_ctx_set (ctx, ZMQ_IO_THREADS, 7);

        s1 = zmq_socket (ctx, ZMQ_PUB);
        assert (s1);

        rc = zmq_bind (s1, "tcp://127.0.0.1:5560");
        assert (rc == 0);

        printf("Kicking off worker threads\n");
        for (i = 0; i != THREAD_COUNT; i++) {
            s2 = zmq_socket (ctx, ZMQ_SUB);
            assert (s2);
            threads [i] = zmq_threadstart(&worker, s2);
        }

        printf("Waiting on them to finish\n");
        for (i = 0; i != THREAD_COUNT; i++) {
            zmq_threadclose(threads [i]);
        }

        printf("Closing sockets\n");
        rc = zmq_close (s1);
        assert (rc == 0);

        printf("Releasing context\n");
        rc = zmq_ctx_term (ctx);
        assert (rc == 0);
    }

    return 0;
}
コード例 #18
0
ファイル: zsys.c プロジェクト: wysman/czmq
void
zsys_set_io_threads (size_t io_threads)
{
    zsys_init ();
    ZMUTEX_LOCK (s_mutex);
    if (s_open_sockets)
        zsys_error ("zsys_io_threads() is not valid after creating sockets");
    assert (s_open_sockets == 0);
    zmq_term (s_process_ctx);
    s_io_threads = io_threads;
    s_process_ctx = zmq_init ((int) s_io_threads);
#if (ZMQ_VERSION >= ZMQ_MAKE_VERSION (3, 2, 0))
    //  TODO: this causes TravisCI to break; libzmq does not return a
    //  valid socket on zmq_socket(), after this...
    zmq_ctx_set (s_process_ctx, ZMQ_MAX_SOCKETS, s_max_sockets);
#endif
    ZMUTEX_UNLOCK (s_mutex);
}
コード例 #19
0
int main (void)
{
    setup_test_environment();
    void *socket;
    int i;
    int j;
    int rc;
    void* threads [THREAD_COUNT];

    for (j = 0; j != 10; j++) {

        //  Check the shutdown with many parallel I/O threads.
        struct thread_data tdata;
        tdata.ctx = zmq_ctx_new ();
        assert (tdata.ctx);
        zmq_ctx_set (tdata.ctx, ZMQ_IO_THREADS, 7);

        socket = zmq_socket (tdata.ctx, ZMQ_PUB);
        assert (socket);

        rc = zmq_bind (socket, "tcp://127.0.0.1:*");
        assert (rc == 0);
        size_t len = MAX_SOCKET_STRING;
        rc = zmq_getsockopt (socket, ZMQ_LAST_ENDPOINT, tdata.endpoint, &len);
        assert (rc == 0);

        for (i = 0; i != THREAD_COUNT; i++) {
            threads [i] = zmq_threadstart(&worker, &tdata);
        }

        for (i = 0; i != THREAD_COUNT; i++) {
            zmq_threadclose(threads [i]);
        }

        rc = zmq_close (socket);
        assert (rc == 0);

        rc = zmq_ctx_term (tdata.ctx);
        assert (rc == 0);
    }

    return 0;
}
コード例 #20
0
ファイル: van.cpp プロジェクト: lacozhang/numopt
void Van::init() {
  scheduler_ = parseNode(FLAGS_scheduler);
  myNode_ = parseNode(FLAGS_my_node);
  LOG(INFO) << "I'm \n[" << myNode_.DebugString() << "]";

  context_ = zmq_ctx_new();
  CHECK(context_ != nullptr) << "Create 0mq context failed";

  zmq_ctx_set(context_, ZMQ_MAX_SOCKETS, 65536);
  bind();
  connect(scheduler_);

  if (isScheduler()) {
    CHECK(!zmq_socket_monitor(receiver_, "inproc://monitor", ZMQ_EVENT_ALL));
  } else {
    CHECK(!zmq_socket_monitor(senders_[scheduler_.id()], "inproc://monitor",
                              ZMQ_EVENT_ALL));
  }
  monitorThread_ = new std::thread(&Van::monitor, this);
  monitorThread_->detach();
}
コード例 #21
0
static ngx_int_t
ngx_zeromq_process_init(ngx_cycle_t *cycle)
{
    ngx_zeromq_conf_t  *zcf;

    zcf = (ngx_zeromq_conf_t *) ngx_get_conf(cycle->conf_ctx,
                                             ngx_zeromq_module);

    if (ngx_zeromq_used) {
        ngx_zeromq_ctx = zmq_ctx_new();

        if (ngx_zeromq_ctx == NULL) {
            ngx_zeromq_log_error(cycle->log, "zmq_ctx_new()");
            return NGX_ERROR;
        }

        if (zmq_ctx_set(ngx_zeromq_ctx, ZMQ_IO_THREADS, zcf->threads) == -1) {
            ngx_zeromq_log_error(cycle->log, "zmq_ctx_set(ZMQ_IO_THREADS)");
        }
    }

    return NGX_OK;
}
コード例 #22
0
ファイル: read.c プロジェクト: ma-everett/tmpcache
tc_readinfo_t * tc_readfromcache (tc_readconfig_t * config)
{
  tc_readinfo_t *info;
  info = NULL;

  uint32_t sbufsize = 256 - (blength(config->cachepath) + 2);
  char sbuf[ sbufsize ];
  
  c_readf readf = (config->miss) ? readempty : readcontentsfromfile;
  void *hint = NULL;

  int32_t r = -1;

#if defined HAVE_LIBCDB

  cdb_t cdb;
  int32_t usecdb = c_iscdbfile(config->cachepath);
  if (usecdb) {

    syslog(LOG_INFO,"%s -> trying to open cdb file %s",__FUNCTION__,btocstr(config->cachepath));

    int32_t fd = open(btocstr(config->cachepath),O_RDONLY); /*FIXME : unsigned ? */
    if (!fd) {
      
      syslog(LOG_ERR,"%s, cdb init error, failed to open file",__FUNCTION__);
      goto exitearly;
    }
    
    if (cdb_init(&cdb,fd) != 0) {
      
      syslog(LOG_ERR,"%s, cdb init error",__FUNCTION__);
      goto exitearly;
    }
      
    readf = readcontentsfromcdb;
    hint = (void *)&cdb;
  }

#endif

  void *ctx, *sock;

  ctx = zmq_ctx_new(); /*xs_init();*/
  if (ctx == NULL) {
    
    syslog(LOG_ERR,"%s! %s",__FUNCTION__,zmq_strerror(zmq_errno()));
    goto exitearly;
  }

  zmq_ctx_set(ctx,ZMQ_IO_THREADS,2);

  sock = zmq_socket (ctx,ZMQ_XREP);
  if (sock == NULL) {

    syslog(LOG_ERR,"cannot open XREP socket - %s",zmq_strerror(zmq_errno()));
    zmq_ctx_destroy(ctx); /*xs_term(ctx);*/
    goto exitearly;
  }

  info = (tc_readinfo_t *)c_malloc(sizeof(tc_readinfo_t),NULL);
  info->numofreads = 0;
  info->numofmisses = 0;
 
  
  uint32_t rcvhwm = 500;
  r = zmq_setsockopt (sock,ZMQ_RCVHWM,&rcvhwm,sizeof(rcvhwm));
  zmq_assertmsg (r == 0,"xs setsockopt rcvhwm error");
  

  r = zmq_bind (sock,btocstr(config->address));
  if (r == -1) {

    syslog(LOG_ERR,"cannot not open %s - %s",btocstr(config->address),zmq_strerror(zmq_errno()));
    zmq_close (sock);
    zmq_ctx_destroy(ctx); /*xs_term (ctx);*/
    goto exitearly;
  }

 
  zmq_pollitem_t pitems[1];
  pitems[0].socket = sock;
  pitems[0].events = ZMQ_POLLIN;

  uint32_t count  = 0;
  uint64_t rsize = 0;
  void *data = NULL;

  for (;;) {
    
    if (count == 0)
      count = zmq_poll (pitems,1,(1000 * 3)); /*FIXME*/

    if ((*config->signalf)() == 1)
      break;
    
    if (count == 0) {
    
      continue;
    }

    zmq_msg_t msg_ident;
    r = zmq_msg_init (&msg_ident);
    zmq_assertmsg (r != -1,"ident init error");
    
    zmq_msg_t msg_blank;
    r = zmq_msg_init (&msg_blank);
    zmq_assertmsg (r != -1,"blank init error");
    
    zmq_msg_t msg_key;
    r = zmq_msg_init (&msg_key);
    zmq_assertmsg (r != -1,"key init error");
  

    r = zmq_msg_recv (&msg_ident,sock,0);
    zmq_assertmsg (r != -1,"recvmsg ident error");
    r = zmq_msg_recv (&msg_blank,sock,0);
    zmq_assertmsg (r != -1,"recvmsg blank error");
    r = zmq_msg_recv (&msg_key,sock,0);
    zmq_assertmsg (r != -1,"recvmsg key error");

    count--;

    memset (&sbuf[0],'\0',256); /*FIXME, possible out of bounds error*/
    memcpy (&sbuf[0],zmq_msg_data(&msg_key),zmq_msg_size(&msg_key));

    bstring key = bfromcstr(sbuf);
    int32_t filtered = c_filterkey(key);
    /* filter */
    if (filtered) 
      syslog(LOG_DEBUG,"%s! %s filtered\n",__FUNCTION__,btocstr(key));

#if defined HAVE_LIBCDB
    key = (usecdb) ? bfromcstr(sbuf) : bformat("%s/%s\0",btocstr(config->cachepath),sbuf);
#else 
    key = bformat ("%s/%s\0",btocstr(config->cachepath),sbuf);
#endif
    
    if (!filtered) {
      if (!data)
	data = (void *)c_malloc (config->size,NULL);
      
      rsize = (*readf)(hint,key,data,config->size);
    }    
 
    zmq_msg_t msg_part;
    
    if (rsize) {
      r = zmq_msg_init_data (&msg_part,data,rsize,c_free,NULL); 
      zmq_assertmsg (r != -1,"msg part init error");
      data = NULL;
    } else {
      
      r = zmq_msg_init (&msg_part);
      zmq_assertmsg (r != -1,"msg part init error");
    
      info->numofmisses ++;
    }   

    bdestroy (key);

    r = zmq_msg_send (&msg_ident,sock,ZMQ_SNDMORE);
    zmq_assertmsg (r != -1,"sendmsg ident error");

    r = zmq_msg_send (&msg_blank,sock,ZMQ_SNDMORE);
    zmq_assertmsg (r != -1,"sendmsg blank error");
 
    r = zmq_msg_send (&msg_key,sock,ZMQ_SNDMORE);
    zmq_assertmsg (r != -1,"sendmsg key error");

    r = zmq_msg_send (&msg_part,sock,0);
    zmq_assertmsg (r != -1,"sendmsg part error");


    zmq_msg_close (&msg_ident);
    zmq_msg_close (&msg_blank);
    zmq_msg_close (&msg_key);
    zmq_msg_close (&msg_part);

    info->numofreads ++;
  } /*for loop*/

 error:
  
  zmq_unbind (sock,btocstr(config->address)); /*FIXME, check return*/
  
  r = zmq_close (sock);
  if (r == -1) {

    syslog(LOG_ERR,"%s! %s",__FUNCTION__,zmq_strerror(zmq_errno()));
    zmq_ctx_destroy(ctx); /*xs_term (ctx);*/
    goto exitearly;
  }

  r = zmq_ctx_destroy(ctx); /*xs_term (ctx);*/
  if (r == -1) {

    syslog(LOG_ERR,"%s! %s",__FUNCTION__,zmq_strerror(zmq_errno()));
    goto exitearly;
  }

#if defined HAVE_LIBCDB
  if (usecdb)
    cdb_free (&cdb);
#endif

 exitearly:

  return info;  
}
コード例 #23
0
ファイル: zmq.cpp プロジェクト: ezrover/libzmq
void *zmq_init (int io_threads_)
{
    void *ctx = zmq_ctx_new ();
    zmq_ctx_set (ctx, ZMQ_IO_THREADS, io_threads_);
    return ctx;
}
コード例 #24
0
ファイル: remote_thr.cpp プロジェクト: ZheYuan/libzmq
int main (int argc, char *argv [])
{
    void *ctx;
    int rc;
    int i;

    if (argc != 10) {
        printf ("usage: remote_thr <connect-to> <message-size> <message-count> <SND buffer> <RCV buffer> <flow (PUSH/PULL)> <records (ZMSG/DATA)> <zmq-threads> <workers>\n");
        return 1;
    }

    connect_to = argv [1];
    message_size = atoi (argv [2]);
    message_count = atoi (argv [3]);
	sndbuflen = atoi (argv [4]);
	rcvbuflen = atoi (argv [5]);
    if( !strcmp( argv [6], "PUSH")){
        flow = ZMQ_PUSH;
    }
    if( !strcmp( argv [6], "PULL")){
        flow = ZMQ_PULL;
    }
    if( !strcmp( argv [7], "ZMSG")){
        rec = ZMSG;
    }
    if( !strcmp( argv [7], "DATA")){
        rec = DATA;
    }
    threads = atoi (argv [8]);
    workers = atoi (argv [9]);


    ctx = zmq_ctx_new ();
    if (!ctx) {
        printf ("error in zmq_ctx_new: %s\n", zmq_strerror (errno));
        return -1;
    }

    rc = zmq_ctx_set ( ctx, ZMQ_IO_THREADS, threads);
    if (rc) {
        printf ("error in zmq_ctx_set: %s\n", zmq_strerror (errno));
        return -1;
    }

    printf("Threads: %d, workers %d\n", zmq_ctx_get( ctx, ZMQ_IO_THREADS), workers);
#if defined ZMQ_HAVE_WINDOWS
    HANDLE worker[128];
#else
    pthread_t worker[128];
#endif

    US_TIMER timer;

    tm_init( &timer);

    for (i = 0; i < workers; i++) {
#if defined ZMQ_HAVE_WINDOWS
        worker[i] = (HANDLE) _beginthreadex (NULL, 0, worker_routine, ctx, 0 , NULL);
#else
        pthread_create (&worker[i], NULL, worker_routine, ctx);
#endif
        printf("Worker %d spawned\n", i);
    }

    for (i = 0; i < workers; i++) {
#if defined ZMQ_HAVE_WINDOWS
        WaitForSingleObject (worker[i], INFINITE);
        CloseHandle (worker[i]);
#else
        pthread_join( worker[i], NULL);
#endif
        printf("Worker %d joined\n", i);
    }

    float secs = tm_secs( &timer);
    float total = ( (float)workers)*(((float) message_count) * ((float) message_size)) / (1024.0*1024.0*1024.0);

    printf ("Message: size: %d KBytes, count: %d/workers(%d), time: %f secs\n", (int) message_size/1024, message_count, workers, secs);
    printf ("%sed %.3f GB @ %.3f GB/s\n", (flow == ZMQ_PULL) ? "Pull":"Push", total, total/secs);

    rc = zmq_term (ctx);
    if (rc != 0) {
        printf ("error in zmq_term: %s\n", zmq_strerror (errno));
        return -1;
    }

    return 0;
}
コード例 #25
0
ファイル: proxy_thr.cpp プロジェクト: somdoron/libzmq
int main (int argc, char *argv[])
{
    if (argc != 3) {
        printf ("usage: inproc_thr <message-size> <message-count>\n");
        return 1;
    }

    message_size = atoi (argv[1]);
    message_count = atoi (argv[2]);
    printf ("message size: %d [B]\n", (int) message_size);
    printf ("message count: %d\n", (int) message_count);

    void *context = zmq_ctx_new ();
    assert (context);

    int rv = zmq_ctx_set (context, ZMQ_IO_THREADS, 4);
    assert (rv == 0);

    //  START ALL SECONDARY THREADS

    const char *pub1 = "inproc://perf_pub1";
    const char *pub2 = "inproc://perf_pub2";
    const char *sub1 = "inproc://perf_backend";

    proxy_hwm_cfg_t cfg_global = {};
    cfg_global.context = context;
    cfg_global.frontend_endpoint[0] = pub1;
    cfg_global.frontend_endpoint[1] = pub2;
    cfg_global.backend_endpoint[0] = sub1;
    cfg_global.control_endpoint = "inproc://ctrl";

    //  Proxy
    proxy_hwm_cfg_t cfg_proxy = cfg_global;
    void *proxy = zmq_threadstart (&proxy_thread_main, (void *) &cfg_proxy);
    assert (proxy != 0);

    //  Subscriber 1
    proxy_hwm_cfg_t cfg_sub1 = cfg_global;
    cfg_sub1.thread_idx = 0;
    void *subscriber =
      zmq_threadstart (&subscriber_thread_main, (void *) &cfg_sub1);
    assert (subscriber != 0);

    //  Start measuring
    void *watch = zmq_stopwatch_start ();

    //  Publisher 1
    proxy_hwm_cfg_t cfg_pub1 = cfg_global;
    cfg_pub1.thread_idx = 0;
    void *publisher1 =
      zmq_threadstart (&publisher_thread_main, (void *) &cfg_pub1);
    assert (publisher1 != 0);

    //  Publisher 2
    proxy_hwm_cfg_t cfg_pub2 = cfg_global;
    cfg_pub2.thread_idx = 1;
    void *publisher2 =
      zmq_threadstart (&publisher_thread_main, (void *) &cfg_pub2);
    assert (publisher2 != 0);

    //  Wait for all packets to be received
    zmq_threadclose (subscriber);

    //  Stop measuring
    unsigned long elapsed = zmq_stopwatch_stop (watch);
    if (elapsed == 0)
        elapsed = 1;

    unsigned long throughput =
      (unsigned long) ((double) message_count / (double) elapsed * 1000000);
    double megabits = (double) (throughput * message_size * 8) / 1000000;

    printf ("mean throughput: %d [msg/s]\n", (int) throughput);
    printf ("mean throughput: %.3f [Mb/s]\n", (double) megabits);

    //  Wait for the end of publishers...
    zmq_threadclose (publisher1);
    zmq_threadclose (publisher2);

    //  ... then close the proxy
    terminate_proxy (&cfg_proxy);
    zmq_threadclose (proxy);

    int rc = zmq_ctx_term (context);
    assert (rc == 0);

    return 0;
}
コード例 #26
0
ファイル: zmq_common.cpp プロジェクト: duxet/hhvm-zmq
ContextData::ContextData(int64_t io_threads) {
  m_context = zmq_ctx_new();
  
  zmq_ctx_set(m_context, ZMQ_IO_THREADS, io_threads);
}
コード例 #27
0
ファイル: zsys.c プロジェクト: wysman/czmq
void *
zsys_init (void)
{
    if (s_initialized) {
        assert (s_process_ctx);
        return s_process_ctx;
    }
    //  Pull process defaults from environment
    if (getenv ("ZSYS_IO_THREADS"))
        s_io_threads = atoi (getenv ("ZSYS_IO_THREADS"));

    if (getenv ("ZSYS_MAX_SOCKETS"))
        s_max_sockets = atoi (getenv ("ZSYS_MAX_SOCKETS"));

    if (getenv ("ZSYS_LINGER"))
        s_linger = atoi (getenv ("ZSYS_LINGER"));

    if (getenv ("ZSYS_SNDHWM"))
        s_sndhwm = atoi (getenv ("ZSYS_SNDHWM"));

    if (getenv ("ZSYS_RCVHWM"))
        s_rcvhwm = atoi (getenv ("ZSYS_RCVHWM"));

    if (getenv ("ZSYS_PIPEHWM"))
        s_pipehwm = atoi (getenv ("ZSYS_PIPEHWM"));

    if (getenv ("ZSYS_IPV6"))
        s_ipv6 = atoi (getenv ("ZSYS_IPV6"));

    if (getenv ("ZSYS_LOGSTREAM")) {
        if (streq (getenv ("ZSYS_LOGSTREAM"), "stdout"))
            s_logstream = stdout;
        else
        if (streq (getenv ("ZSYS_LOGSTREAM"), "stderr"))
            s_logstream = stderr;
    }
    else
        s_logstream = stdout;

    if (getenv ("ZSYS_LOGSYSTEM")) {
        if (streq (getenv ("ZSYS_LOGSYSTEM"), "true"))
            s_logsystem = true;
        else
        if (streq (getenv ("ZSYS_LOGSYSTEM"), "false"))
            s_logsystem = false;
    }
    //  Catch SIGINT and SIGTERM unless ZSYS_SIGHANDLER=false
    if (  getenv ("ZSYS_SIGHANDLER") == NULL
       || strneq (getenv ("ZSYS_SIGHANDLER"), "false"))
        zsys_catch_interrupts ();

    ZMUTEX_INIT (s_mutex);
    s_sockref_list = zlist_new ();
    if (!s_sockref_list) {
        zsys_shutdown ();
        return NULL;
    }
    srandom ((unsigned) time (NULL));
    atexit (zsys_shutdown);

    assert (!s_process_ctx);
    //  We use zmq_init/zmq_term to keep compatibility back to ZMQ v2
    s_process_ctx = zmq_init ((int) s_io_threads);
#if (ZMQ_VERSION >= ZMQ_MAKE_VERSION (3, 2, 0))
    //  TODO: this causes TravisCI to break; libzmq does not return a
    //  valid socket on zmq_socket(), after this...
    zmq_ctx_set (s_process_ctx, ZMQ_MAX_SOCKETS, s_max_sockets);
#endif
    s_initialized = true;

    //  The following functions call zsys_init(), so they MUST be called after
    //  s_initialized is set in order to avoid an infinite recursion
    if (getenv ("ZSYS_INTERFACE"))
        zsys_set_interface (getenv ("ZSYS_INTERFACE"));

    if (getenv ("ZSYS_LOGIDENT"))
        zsys_set_logident (getenv ("ZSYS_LOGIDENT"));

    if (getenv ("ZSYS_LOGSENDER"))
        zsys_set_logsender (getenv ("ZSYS_LOGSENDER"));

    return s_process_ctx;
}