AI Briefing
KO

Resolving Performance Bottlenecks in Spring SimpleBroker's AntMatcher

·2020.06.22 00:00

Key point

Eliminated AntMatcher pattern matching and applied equals comparison to improve lock contention and memory usage.

1 / 13

Details

This case study details the analysis and optimization of Spring SimpleBroker's internal operations to resolve server instability issues in a real-time comment service. Threaddump analysis revealed that lock contention in DefaultSubscriptionRegistry$DestinationCache was blocking the InboundChannel.

Root Cause: Inefficiency of AntMatcher

The existing implementation used Ant-style pattern matching during subscription. As a result, every time the getSubscriptions() method was called during message dispatch, it had to iterate through all sessions and check patterns upon a cache miss. Increasing the cache size increased the loop cost on misses, while decreasing it increased the miss frequency, creating a structural limitation that could not be resolved by merely adjusting the cache size.

Solution: Removing Pattern Matching and Applying equals

The AntMatcher logic was removed and replaced with destination.equals() comparison. This reduced the overhead caused by pattern matching and decreased memory usage. However, since Spring's default implementation, DefaultSubscriptionRegistry, is difficult to extend via inheritance, the code was copied and modified to apply this change.

Results and Implications

After the changes, queue delays still occurred during traffic spikes (e.g., breaking news), but the system recovered quickly. This demonstrates that concurrency control logic within the framework can be a source of performance bottlenecks and suggests that internal implementations can be modified for optimization when necessary.

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.