Skip to content

WIP: [#2187] MessageAudit modernization and performance optimization#2252

Draft
mattrpav wants to merge 4 commits into
apache:mainfrom
mattrpav:amq-gh-2187-messageaudit-perf
Draft

WIP: [#2187] MessageAudit modernization and performance optimization#2252
mattrpav wants to merge 4 commits into
apache:mainfrom
mattrpav:amq-gh-2187-messageaudit-perf

Conversation

@mattrpav

@mattrpav mattrpav commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
  • AtomicBitArrayBin provides lock-free bin array for storing messageIds
  • ConcurrentMessageAudit demonstrates a MessageAudit using JDK-only concurrent hashmap
  • CaffeineMessageAudit demonstrates a MessageAudit using Caffeine cache library
  • MessageAuditPerformanceTest compares results between the implementations
  • activmeq-client/src/test/resources/benchmark-results.html provides results of a test run on MacBookPro M3

@mattrpav mattrpav self-assigned this Jul 24, 2026
@mattrpav mattrpav changed the title WIP: [#2187] MessageAudit modernization WIP: [#2187] MessageAudit modernization and performance optimization Jul 24, 2026
@mattrpav
mattrpav requested a review from cshannon July 24, 2026 15:39
mattrpav added 4 commits July 24, 2026 10:40
- Lock-free CAS-based ring buffer replacement for BitArrayBin using
AtomicLongArray vs synchronization.

- Includes unit tests for correctness, equivalence with BitArrayBin,
and concurrent stress tests
Fully lock-free message audit using ConcurrentHashMap for producer
lookup using computeIfAbsent and AtomicBitArrayBin for CAS-based
per-producer bit operations. No synchronized blocks for audit hot
path.
Message audit using Caffeine cache with size-based TinyLfu eviction
paired with lock-free AtomicBitArrayBin for per-producer bit
operations. Provides bounded producer tracking with automatic
eviction, compared to ConcurrentMessageAudit
ConcurrentHashMap.
@mattrpav
mattrpav force-pushed the amq-gh-2187-messageaudit-perf branch from 9241581 to ab6fee1 Compare July 24, 2026 15:40

@cshannon cshannon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CaffeineMessageAudit is not going to work without some tweaks as it isn't entirely thread safe. The map updates (adding/removing) from the cache would be ok but it doesn't protect another thread from removing or update after you get an object from the cache.

For example in your rollback method:

    var bab = cache.getIfPresent(pid.toString());
    // At this point another thread could remove/update the entry in the cache
    if (bab != null) {
        bab.setBit(id.getProducerSequenceId(), false);
    }

@cshannon

cshannon commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Also, from first glance the AtomicBitArrayBin class looks incredibly complex, did you use something to generate that? I have a lot of hesitation with introducing something that complicated vs simply locking without a real benefit. simple locking may be better under high contention anyways (that's where the benchmarking comes into play)

The main issue here is verifying it's actually correct and truly thread safe and won't introduce weird bugs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants