Reputation: 28030
I am using the node.js mosca MQTT broker for some internet of things (iot) application.
https://github.com/mcollina/mosca
What is the maximum number of topics that a MQTT broker, specifically mosca, can handle?
If I want to increase the number of allowed topics, is there a configuration parameter I can modify or which part of the code can I change?
Upvotes: 4
Views: 10306
Reputation: 1463
If you regard a MQTT broker as a layer 4 switch (switching messages between clients) and the topic is the address (key) that it switches on, it would be a badly designed broker if you had to do anything to enable a large number of topics.
The common application we run across is at least 1 topic per separate publisher, with thousands if not hundreds of thousands of publishers.
Upvotes: 0
Reputation: 96
While hardlib's answer is correct, i would like to add that the number of possible topics is of course limited by the broker's / clients maximum topic length.
If that strictly follows the MQTT spec we are talking about 7^65536 possible topics (as explained here ), but for smaller brokers / clients (for example embedded stuff) the maximum topic length can be a lot smaller than 65536 bytes. PubSubClient for example has a default maximum length of 128 bytes for the entire packet.
Upvotes: 0
Reputation: 59618
Without looking at the source for mosca I'm going to make a general statement about a generic broker.
The number of topics is going to be set by the number of topics that clients subscribe to as this list is what is searched when a new message is published, so assuming this list is kept I some kind of tree structure (which is very likely due to the hierarchical nature of topics) then the limit is likely to be the amount of memory on the server (assuming 64bit host).
Also since mosca runs on nodejs and as such single threaded, having a huge number of topics is likely to impact performance before you run out of memory.
Upvotes: 2