-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
62w subscriptions cost about 85min #629
Comments
85 minutes for 600k subscriptions seems very slow. Could you give us some statistics on those subscriptions? How many clients, how many topics, how deep are those topics? |
Did a quick profile, and I suspect you have a very flat tree.
For every check, it loops over the children. If there are many thousands, that takes time. This can easily be fixed by making children a Map<Token, INode> . However, for each add, the CNode is copied, and copying that map means iterating over all items, which takes just as much time.We'd need a map implementation that can be quickly cloned... |
621206 subscriptions
We notice that CTrie is thread-safe. It took 15 minutes to load 620k subscriptions with 8 threads, but CPU usage is 100%. We look forward to your suggestions. |
Let's try. We'll feed back here if we make progress. |
If you are experimenting with it, you could also try making |
I had a quick go at it in #630 |
Descriptiondata structure for CNode.children List<INode> + for each
ConcurrentHashMap<Token, INode> + containsKey
List<INode> + Collections.binarySearch
List<INode> and Collections.binarySearch with 8 threads cost only 44s, but it's not thread-safe. We have a suggestion for #630. |
Yeah, good catch. |
I've also just noticed there are massive speed differences based on the order in which I offer the subscriptions. The slowest and fastest I found are:
Added 100000 subscriptions in 1579 ms (63/ms) Versus:
Added 100000 subscriptions in 394 ms (254/ms) Only the order of the subscriptions is different, not the actual subscriptions. And the order is not completely inverted either. In both cases the client-id loop ( In moquette the subscriptions are coming from a Set, so the order is undefined. |
- Changed CNode.children List<INode> to Map<Token, INode> - Changed CNode.add to return boolean - Optimize execution logic for CNode.anyChildrenMatch, CNode.childOf - Optimize execution logic for CTire.recursiveMatch
Hi @zexin321 I saw your PR #633 I would like to have some profiling tests that we can share to have a common base to discuss on. |
Hi @andsel I found the root cause of this problem( When there are a lot of children and subscriptions, CNode.copy will be slow) , you can to run amzexin/moquette fix629_bug-reproduce CTrieTest.testAdd620kSubscribe |
- Changed CNode.children List<INode> to Map<Token, INode> - Changed CNode.add to return boolean - Optimize execution logic for CNode.anyChildrenMatch, CNode.childOf - Optimize execution logic for CTire.recursiveMatch
Expected behavior
We hope load all the data in 2 minutes.
Actual behavior
62w subscriptions cost about 85min.
Steps to reproduce
Minimal yet complete reproducer code (or URL to code) or complete log file
Moquette MQTT version
0.15
JVM version (e.g.
java -version
)openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
OS version (e.g.
uname -a
)Linux MyServerName 3.10.0-1062.18.1.el7.x86_64 #1 SMP Tue Mar 17 23:49:17 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: