-
Notifications
You must be signed in to change notification settings - Fork 0
Labels
difficultA task most likely involving researchA task most likely involving researchscylla-serverDevelopment Focused in the BackendDevelopment Focused in the Backend
Description
Description
Currently the rules manager uses a client to rule structure that requires O(all_clients) iterations for each MQTT message:
clients_map: FxHashMap<ClientId, FxHashMap<Topic, Vec<Rule>>>,
rules_lookup: FxHashMap<Topic, FxHashSet<ClientId>>,The current timing is not the worst as our client subscription size would most likely be at a max of 10 for the foreseeable future, however, logic-wise this is helpful and ultimately good to support early on.
Transition to:
pub struct RuleManager {
rules: FxHashMap<RuleId, Rule>,
topic_index: RwLock<FxHashMap<Topic, FxHashSet<RuleId>>>,
subscriptions: RwLock<BiMultiMap<RuleId, ClientId>>,
}BiMultiMap provides O(1) bidirectional lookups:
- Rule → Clients (for MQTT notifications)
- Client → Rules (for UI focused queries (what rules am I subbed too?)
Ultimately this will be transitioned to a database in the future, which should be seem less as the rules manager acts as a wrapper for whatever logic we decide it needs.
Acceptance Criteria
- functionality stays the same (test with Postman before changes)
- MQTT message processing uses O(1) topic lookup
- all operations stay within O(n) time
- concurrent MQTT processing enabled
Proposed Solution
- Create
BiMultiMap<L, R>struct (ask @bracyw (me) for more details) - Create new RuleManager structure with the new fields above
- Convert old functions to logic for the new structure
Metadata
Metadata
Assignees
Labels
difficultA task most likely involving researchA task most likely involving researchscylla-serverDevelopment Focused in the BackendDevelopment Focused in the Backend
Type
Projects
Status
Todo