stan.js: Error on large number of subscriptions
I am trying to publish messages to 1 million subjects and subscribing to those subjects from another process. I get the following error:
NatsError: Subject must be supplied
at Client.publish (/root/node_modules/nats/lib/nats.js:1022:13)
at Message.ack (/root/node_modules/node-nats-streaming/lib/stan.js:804:24)
at Message.maybeAutoAck (/root/node_modules/node-nats-streaming/lib/stan.js:791:10)
at Object.callback (/root/node_modules/node-nats-streaming/lib/stan.js:690:11)
at Client.processMsg (/root/node_modules/nats/lib/nats.js:957:11)
at Client.processInbound (/root/node_modules/nats/lib/nats.js:885:14)
at Socket.<anonymous> (/root/node_modules/nats/lib/nats.js:468:12)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
Publisher code:
var stan = require('node-nats-streaming').connect('test-cluster', 'test',{maxPubAcksInflight: 1100000});
let total = 1000000;
stan.on('connect', function () {
for(let i=0;i<total;i++)
{
stan.publish('foo'+i, 'Hello node-nats-streaming:' + i);
if(i%1000 == 0)
console.log(i);
}
});
Subscriber code:
var stan = require('node-nats-streaming').connect('test-cluster', 'test3');
let total = 1000000;
let a = [];
let j = 0;
stan.on('connect', function () {
for(let i=0;i<total;i++)
{
var opts = stan.subscriptionOptions();
opts.setDeliverAllAvailable();
opts.setMaxInFlight(1000000);
opts.setDurableName('my-durable' + i);
a.push(stan.subscribe('foo'+i, opts));
// a[i].on('ready',function() {
a[i].on('error', function (err) {
console.log('subscription for ' + this.subject + " raised an error: " + err + '\n' + err.stack);
});
a[i].on('message', function (msg) {
j += 1;
if(j%1000 == 0){
console.log(j);
console.log('Received a message [' + msg.getSequence() + '] ' + msg.getData());
}
// });
});
}
});
Running nats streaming from a docker using:
docker run -p 4222:4222 -ti nats-streaming --max_channels 1000000 --max_subs 1000000
Please help me out figuring the issue.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (11 by maintainers)
Yes, so here is what would make it “work”:
The publisher code:
I did run this with a separate
gnatsd
to better monitor the memory and cpu usage. I also made use of a feature in nats streaming in master to reduce the number of streaming server’s internal subscriptions to receive application acks. NATS server:NATS Streaming Server:
Still, this is a lot of subscriptions (and I have reduce to 500,000 instead of 1M). You may want to split the load on different servers/processes.
Looked at the fix on the server and looks ok to me. Let’s see if @karteek-gamooga make sure that it connects to master server (and not a running docker version that is still 0.3.8) and see if he can still reproduce.