JustinTulloss / zeromq.node

Node.js bindings to the zeromq library
MIT License
1.65k stars 284 forks source link

Runtime error when using 1000+ subscriptions (PUB/SUB) #292

Open sprijk opened 10 years ago

sprijk commented 10 years ago

When I am doing this:

var zmq = require('zmq');

var subs = {};

for (var i = 0; i < 10000; i++) {
  console.log('i', i);
  subs[i] = zmq.socket('sub');
  subs[i].connect("ipc://tmp/sub" + i + ".ipc");
  subs[i].on('message', function() { console.log('param message'); });
}

I get:

...
i 1005
i 1006
i 1007
terminate called after throwing an instance of 'std::runtime_error'
  what():  Socket operation on non-socket

Is this normal?

OS: Ubuntu 13.10 libzmq3: 4.0.4 zeromq.node: 2.6.0

kessler commented 10 years ago

@sprijk check max number of sockets?

http://api.zeromq.org/3-2:zmq-ctx-set#toc4

sprijk commented 10 years ago

Can I set this somewhere in the zeromq.node module?

kessler commented 10 years ago

The ctx variable inside zmq module is not exposed in any way (and I assume its by design). However looking at the binding code I see that creating a new context object translates to a zmq_init() call, so maybe in your code you can just do new zmq.Context(...) ? maybe someone who tried can comment on this approach...

sorenriise commented 10 years ago

Your system most likely are running out of file descriptors -- if you are on linux, check your ulimits (ulimit -a) and see how many open files you are allowed -- the default is 1024 which looks like is what you are hitting. Other system Win/OSx will have similar setting but not aware of how to figure those out.

jmparra commented 9 years ago

@sprijk Can I set this somewhere in the zeromq.node module?

Yes, doing this:

var zmq = require('zmq');
zmq.Context.setMaxSockets(1000000);