Improve CriteriaEvaluator performance by reducing ZooKeeper reads #62
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.
Improve CriteriaEvaluator performance by reducing ZooKeeper reads
Description
What: Optimizes CriteriaEvaluator to reduce message recipient evaluation time by minimizing redundant ZooKeeper reads.
Why: The current implementation performs unnecessary ZooKeeper roundtrips when evaluating message recipients. For common query patterns (e.g., targeting all instances or instance-only criteria), the evaluator reads more data than needed and performs redundant filtering, which increases latency especially in large clusters.
How:
Direct LIVEINSTANCES lookup for all-instances queries: When no specific instance filter is provided (empty, "*", or "%"), the code now uses LIVEINSTANCES directly instead of querying INSTANCES first and then filtering by live participants.
Optimized instance-only criteria: When only instance names are specified without resource/partition/state filters, the evaluator switches from EXTERNALVIEW to LIVEINSTANCES to avoid reading potentially large EXTERNALVIEW data.
Skip redundant live participant checks: When the data source is already LIVEINSTANCES, the code skips fetching live participants again since all results are guaranteed to be live.
Early exit optimization: Returns immediately when no live instances exist, avoiding unnecessary iteration.
Code quality improvements: Uses SLF4J parameterized logging and Guava's string utilities for cleaner, more efficient code.
Tests
Modified tests:
TestDefaultMessagingService- Enhanced mock to support LIVEINSTANCES property type queries to properly test the optimized data source selection logic.Existing test coverage:
TestDefaultMessagingServicevalidates the message routing behavior with the optimized criteria evaluation.Changes that Break Backward Compatibility
None. This change is purely an internal optimization that preserves the existing API and behavior. The same messages are routed to the same recipients; the implementation simply does so more efficiently.