[zeromq-dev] number of sockets for inproc

Ilja Golshtein ilejncs at narod.ru
Mon Nov 19 16:56:04 CET 2012


Hello.

>From time to time people ask about 'too many open files' issue.
I've faced it myself when switched from 2.0 to 2.2

The following application
# cat ./inproc.cpp
===
#include <iostream>
#include <vector>
#include <zmq.hpp>

int main ()
{
  zmq::context_t ctx (1);

  zmq::socket_t s (ctx, ZMQ_REP);
  s.bind ("tcp://127.0.0.1:23001");

  sleep (1);

  std::vector<zmq::socket_t*> keeper;

  for (int i = 0; i < 10 ; ++i)
  {
    zmq::socket_t* s2 = new zmq::socket_t(ctx, ZMQ_REQ);
    s2->connect ("tcp://127.0.0.1:23001");
    keeper.push_back(s2);
  }

  sleep (1);
  int major=0;
  int minor=0;
  int patch=0;

  zmq::version(&major, &minor, &patch);

  std::cerr << major << ':' << minor << std::endl;
  std::cout << getpid() << std::endl;
  sleep (5);

  for (int i = 0; i < 10 ; ++i)
  {
    delete keeper.back();
    keeper.pop_back();
  }
===
running together with netstat
===
netstat -anp | grep `./inproc` | wc -l
===
shows that 0mq 2.0 requires one socket, while 2.1 and 2.2 create 11.

Is the change between 2.0 and 2.1 expected?
Is the behavior considered normal or it is a bug and it could be fixed?
How does 3.x behave?

>From my point of view it is fine if 0mq could reduce number of required descriptors
and it is useful for certain design patterns, assuming performance penalty is neglectable.

Thanks.


-- 
Best regards
Ilja Golshtein



More information about the zeromq-dev mailing list