-
Notifications
You must be signed in to change notification settings - Fork 2.4k
perf(ruleeng): employ emqx_topic_index to speed up topic matching
#11396
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
Merged
keynslug
merged 12 commits into
emqx:release-52
from
keynslug:ft/EMQX-10712/ruleeng-topic-index-vol-2
Aug 17, 2023
Merged
perf(ruleeng): employ emqx_topic_index to speed up topic matching
#11396
keynslug
merged 12 commits into
emqx:release-52
from
keynslug:ft/EMQX-10712/ruleeng-topic-index-vol-2
Aug 17, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
Pull Request Test Coverage Report for Build 5764332092
💛 - Coveralls |
Contributor
Author
|
Few more careful measurements regarding memory-per-process consumption. Before / After. Both are docker images built locally with:
Configuration has only one rule, forwarding messages to the local mosquitto instance: Workload is: https://snapshots.raintank.io/dashboard/snapshot/3jyRFjm6FNEIosspYobGjh8bmkxNiace Observations:
|
zmstone
previously approved these changes
Aug 14, 2023
bcf5890 to
d0dce1f
Compare
Somewhat similar to `emqx_trie` in design and logic, yet built on top of a single, potentially pre-existing table.
Otherwise, topic with empty tokens (e.g. `a/b///c`) would have some of their tokens ordered before `#` / `+`, because empty token was represented as empty atom (`''`).
Thanks to @HJianBo for spotting this issue. The approach to fix it is different though: we try to keep the "recurrency branch factor" to a minimum, instead introducing new condition for the case when filter does not match, but iteration with `ets:next/2` is not yet finished for the prefix. Co-Authored-By: JianBo He <heeejianbo@gmail.com>
Co-Authored-By: JianBo He <heeejianbo@gmail.com>
This should give less `ets:next/2` calls in general and much less when index has relatively small number of long non-wildcard topics.
* emqx_rule_engine 5.0.23
7b8f3c1 to
d302aaa
Compare
To (hopefully) better illustrate what is happening there.
This should further optimize the number of `ets:next/2` calls required for a single match query.
zmstone
approved these changes
Aug 17, 2023
9 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Fixes EMQX-10712.
Follows up #11332, #11282, #11313 .
Summary
🤖 Generated by Copilot at 674847b
This pull request introduces a new module
emqx_topic_indexthat provides a fast and efficient way to match topics to topic filters for the rule engine. It also refactors the rule creation, update, and deletion logic in theemqx_rule_enginemodule to use the topic index and a common validation function. Additionally, it adds a test suite for the topic index module and a macro for the topic index table name.PR Checklist
Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:
Added property-based tests for code which performs user input validationchanges/(ce|ee)/(feat|perf|fix)-<PR-id>.en.mdfilesCreated PR to emqx-docs if documentation update is required, or link to a follow-up jira ticket