This is an automated email from the ASF dual-hosted git repository.
mattrpav pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq.git
The following commit(s) were added to refs/heads/main by this push:
new 0ee159fc41 [#2434] Avoid per-command MDC add+remove in
TransportConnection.service (#2435)
0ee159fc41 is described below
commit 0ee159fc4157ebc59d7d02f0fc99fffd8e19b47e
Author: Matt Pavlovich <[email protected]>
AuthorDate: Mon Aug 10 09:40:51 2026 -0500
[#2434] Avoid per-command MDC add+remove in TransportConnection.service
(#2435)
---
.../org/apache/activemq/broker/TransportConnection.java | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git
a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java
b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java
index 26a14c8cfe..40b7d32a82 100644
---
a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java
+++
b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java
@@ -128,6 +128,8 @@ public class TransportConnection implements Connection,
Task, CommandVisitor {
private final Transport transport;
private MessageAuthorizationPolicy messageAuthorizationPolicy;
private WireFormatInfo wireFormatInfo;
+ // Cached connector URI for the MDC tag; connector.getUri() is stable once
started.
+ private String connectorUriString = "unset";
// Used to do async dispatch.. this should perhaps be pushed down into the
// transport layer..
private boolean inServiceException;
@@ -329,7 +331,14 @@ public class TransportConnection implements Connection,
Task, CommandVisitor {
@Override
public Response service(Command command) {
- MDC.put("activemq.connector", connector.getUri().toString());
+ // 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.
+ if (!connectorUriString.equals(MDC.get("activemq.connector"))) {
+ MDC.put("activemq.connector", connectorUriString);
+ }
Response response = null;
boolean responseRequired = command.isResponseRequired();
int commandId = command.getCommandId();
@@ -379,7 +388,6 @@ public class TransportConnection implements Connection,
Task, CommandVisitor {
}
context = null;
}
- MDC.remove("activemq.connector");
return response;
}
@@ -1132,6 +1140,7 @@ public class TransportConnection implements Connection,
Task, CommandVisitor {
if (status.compareAndSet(NEW, STARTING)) {
try {
synchronized (this) {
+ connectorUriString = connector.getUri().toString();
if (taskRunnerFactory != null) {
taskRunner = taskRunnerFactory.createTaskRunner(this,
"ActiveMQ Connection Dispatcher: "
+ getRemoteAddress());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact