Repository navigation
Description
Problem
The http:// / https:// transport carries broker-to-client traffic as a long-poll GET. HttpTunnelServlet.doGet takes one command off the client's queue and returns it. HttpClientTransport.run() reads that one command and issues the next GET.
So on each connection, broker-to-client throughput is capped at one command per HTTP round trip, even when many commands are already queued for that client. Message dispatches, Responses to sync requests (for example, a transaction commit), and control commands all queue behind each other on that single path.
Locally this is negligible. Over a WAN or through an HTTP proxy, the round trip is tens to hundreds of milliseconds, and it becomes the throughput ceiling. The usual workaround is more connections, and each one adds a long-poll that holds a broker Jetty thread for up to 30 s.
Proposal
Opt-in on the client, backwards compatible both ways:
-
Client: Add a new transport option
maxCommandsPerPoll(default1, preserving today's behaviour). When set above1, theGETcarries the request headerActiveMQ-Max-Commands: <n>. -
Broker:
HttpTunnelServlet.doGetkeeps the existing blocking poll for the first command. Then, without waiting, it adds commands already in the queue (via non-blockingpoll()), up to the requested number and capped by a new connector optionhttp.maxCommandsPerPoll. The response headerActiveMQ-Command-Count: <k>indicates how many commands are in the body. -
Format:
TextWireFormat.marshalalready writes a length prefix before each command, so the body is simply$k$ frames back to back. No new format is required. - Ordering: Order is unchanged—one queue, one reader thread, and commands are handed on in order.
-
Shutdown handling: A
ShutdownInfotaken out while batching is put back on the queue and the batch stops there.
Compatibility
| Client | Broker | Behaviour |
|---|---|---|
| old | new | No request header, so one command and no count header. Same bytes as today. |
| new | old | Header ignored, one command, no count header. The client treats a missing count as 1. |
| new | new | Up to GET. |
Measurements
Setup: Patch applied to 6.3.3 on localhost. One consumer, 200 pre-loaded messages, prefetch 100. The client sleeps 20 ms before every HTTP request to simulate the round trip. GETs and POSTs are counted on the client.
| Consumer | Today: time (GETs / POSTs) |
maxCommandsPerPoll=100: time (GETs / POSTs) |
Speed-up |
|---|---|---|---|
AUTO_ACKNOWLEDGE |
8.2 s (201 / 201) | 9.0 s (102 / 201) | 0.9× |
DUPS_OK_ACKNOWLEDGE |
7.6 s (201 / 201) | 9.7 s (101 / 201) | 0.8× |
| Transacted, commit every message | 29.9 s (401 / 601) | 24.8 s (302 / 601) | 1.2× |
| Transacted, commit every 50 | 10.6 s (205 / 17) | 0.75 s (9 / 17) | 14× |
The gain depends on how many commands are queued when the GET arrives. A consumer that acknowledges every message frees one prefetch slot at a time. The broker then queues one dispatch at a time, and every acknowledgement is its own blocking POST, so there is little to batch. Consumers that acknowledge or commit in batches—or several consumers sharing one connection—leave a backlog in the queue, and that is where it helps.
Alternatives Considered
- Several
GETs in parallel on one connection: The server-side transport stack has noResponseCorrelator. Broker-to-client commands therefore carry no sequence the client could reorder by, so parallel polls would deliver out of order. - WebSocket: The
ws://connector speaks STOMP and MQTT, not OpenWire. - Batching
POSTs (several commands perPOST): Worthwhile, butdoPostreads one XML document without a length prefix, so it needs new framing and changes when send failures are reported. That would be a separate proposal.
Open Questions for Maintainers
- Server default: Should
http.maxCommandsPerPolldefault to batching enabled (proposed100, because the client must opt in anyway) or to1, so the broker operator must opt in too? - Header names: Are
ActiveMQ-Max-CommandsandActiveMQ-Command-Countappropriate, or would you prefer something else? - Branches: Should this target
mainand backport to6.4.xand5.19.x? The change applies to6.3.3without conflicts.
Note: I have a patch ready with unit tests (servlet and client) and end-to-end tests (batched, transacted, old client against new broker), and I can open a PR.
Activity
mattrpav commentedon Nov 26, 2026
@kiril-me what is the core use case you are trying to solve for? The standard http:// transport performs OpenWire over http by serializing the commands to xml. There is a REST endpoint and also the ws:// transports (that do STOMP/MQTT) over websockets. Also, pure stomp:// is available for pure text-based processing of messages.
kiril-me commentedon Nov 26, 2026
Thanks for the pointers. The core use case:
We're a JMS client of a broker we don't operate. A third-party provider runs ActiveMQ Classic and exposes it to us only through the http:// connector. Our network only allows outbound HTTP(S) through a proxy, so tcp://, ssl://and plain stomp:// aren't options. We can't change the broker's connectors, only ask the provider to upgrade the version.
We need full JMS behaviour. Consumers use transacted sessions, prefetch, redelivery with backoff, and dead-letter queues. As far as I can tell, this is the case the HTTP transport docs describe: a JMS client tunnelling through a firewall, with REST/Ajax suggested for non-JMS clients.
On the alternatives:
REST endpoint: no transacted consume or prefetch, and still one message per request, so the same round-trip limit applies.
ws://: as far as I can see, it's broker-side only and speaks STOMP/MQTT (WSServlet). WSTransportFactory only binds, so there's no OpenWire client for it. Using it would mean dropping the JMS client entirely, and the provider would have to enable a new connector.
stomp://: raw TCP, which our network doesn't allow.
Where it hurts. Our round trip to the broker is hundreds of milliseconds. Each http:// connection receives one command per GET, so under a backlog delivery is capped at about one command per round trip per connection. That counts message dispatches and also the Responses to commits.
The only lever today is more connections. Each HTTP connection runs its own GET loop, send-only ones included. We already hold about 50 concurrent long polls against the provider's broker, each tying up a broker Jetty thread for up to 30 s. Adding more pushes against a thread pool we don't control.
The proposal (details in the issue):
Opt-in: the client asks for up to N already-queued commands per GET via a request header. The broker caps N and returns the count in a response header.
No new format: the body reuses the existing length-prefixed TextWireFormat framing, so it's k commands back to back.
Compatible both ways: an old client against a new broker, or a new client against an old broker, behaves exactly as today.
Ordering unchanged: one queue, one reader thread.
It pays off mainly for consumers that acknowledge or commit in batches. In the benchmark in the issue, a transacted consumer committing every 50 messages ran about 14× faster, with 9 GETs instead of 205 for 200 messages. That's because acknowledging every message lets only one dispatch queue up at a time. I'd expect this to help anyone stuck with JMS over HTTP-only egress, which is common in enterprise networks.
This is a small, low-risk improvement to a transport that's already supported. I'm happy to adjust option names, the server default or anything else, and I have a patch with unit and end-to-end tests ready to open as a PR.
mattrpav commentedon Nov 26, 2026
@kiril-me got it. Yep, you are right in the key use case of the http:// transport. I am on-board with adding an enhancement to reduce the round-trips.
I'd like to see a more dynamic configuration by reusing existing prefetchSize and maxFrameSize values to adjust the output. This would dynamically scale the window for tons of small messages or one large message.