Skip to content

[#2434] Avoid per-command MDC add+remove in TransportConnection.service - #2435

Merged
mattrpav merged 1 commit into
apache:mainfrom
mattrpav:amq-gh-2434-reduce-mdc-transportconnection
Aug 10, 2026
Merged

[#2434] Avoid per-command MDC add+remove in TransportConnection.service#2435
mattrpav merged 1 commit into
apache:mainfrom
mattrpav:amq-gh-2434-reduce-mdc-transportconnection

Conversation

@mattrpav

@mattrpav mattrpav commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

MDC entries are copy-on-write maps in log4j2 — a put per command is a
full thread-context map copy per message. Put only when this thread's
tag actually changes and leave it sticky between commands (same
lifecycle-scoped pattern as the activemq.broker MDC entry), so the
steady-state per-command cost is a single allocation-free MDC.get.

In benchmarks this yields 3-6%

@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.

Nice find.

I was thinking this could be simplified and improved even more because we only need to set the value once. We could set it inside the TransportConection start() method after the the transport connection starts, maybe after this line.

The connector is passed in the constructor and is final, so this should never change. If we just set this after start I think you could get rid of the caching of the connectionUri entirely and skip the conditional check, just set it once and be done.

@mattrpav
mattrpav force-pushed the amq-gh-2434-reduce-mdc-transportconnection branch from 41d6db0 to 3423429 Compare August 10, 2026 02:46
@mattrpav

Copy link
Copy Markdown
Contributor Author

@cshannon I applied the change, but went ahead and moved it up ahead of the brokerInfo being sendAsync(), since there is a chance a service(Command) could come in before it is fully set (ie vm:// transport).

@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.

LGTM, could use a description in the comments on the PR instead of just the code itself to help explain why this change was done

@mattrpav
mattrpav merged commit 0ee159f into apache:main Aug 10, 2026
28 of 30 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Apache ActiveMQ v6.4.0 Aug 10, 2026
@mattrpav
mattrpav deleted the amq-gh-2434-reduce-mdc-transportconnection branch August 10, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants