Skip to content

Return several commands per HTTP GET when the client asks for it - #2912

Open
kiril-me wants to merge 2 commits into
apache:mainfrom
kiril-me:several_commands_per_http_get
Open

kiril-me wants to merge 2 commits into
apache:mainfrom
kiril-me:several_commands_per_http_get

Conversation

@kiril-me

@kiril-me kiril-me commented Dec 1, 2026 •

Copy link
Copy Markdown

Issue: #2902

Why

JMS clients that can only reach a broker over the http:// transport receive exactly one command
per long-poll GET. Over a WAN this caps broker->client throughput at one command per round trip
per connection, even when many commands are already queued. Use case and alternatives (REST,
ws://, stomp://) are discussed in #2902.

What

  • Client: new transport option batchedPoll (default false). When true, each GET sends
    ActiveMQ-Batched-Poll: true.
  • Broker: HttpTunnelServlet.doGet keeps the existing blocking poll for the first command,
    then appends whatever is already queued for that client, without waiting:
    • Count is bounded by consumer prefetch: the per-client queue only holds what the broker has
      dispatched, so no new count option is needed.
    • Size is capped by the connector's existing wireFormat.maxFrameSize (until now only
      enforced on POST). The first command is always sent, as today. A command that would exceed the
      limit goes back to the head of the queue.
    • The per-client queue is now a LinkedBlockingDeque, so a command put back keeps its order.
      A ShutdownInfo taken while batching is also put back at the head and ends the batch.
  • The response carries ActiveMQ-Command-Count: <k>. The body format is unchanged:
    TextWireFormat already writes a length prefix per command, so it is k commands back to back.
  • No new broker options.

Compatibility

Client Broker Behaviour
old new no request header -> one command, no count header (same bytes as today)
new old header ignored -> one command; missing count header is read as 1
new new all queued commands within prefetch and maxFrameSize

Tests

  • HttpTunnelServletBatchedPollTest: today's single-command response, returns everything queued
    in order, stops before exceeding maxFrameSize with the remainder kept at the head, first command
    sent even when larger than maxFrameSize, ShutdownInfo left at the head, header other than
    true falls back to one command, a non-deque queue falls back to one command.
  • HttpClientTransportBatchedPollTest: reads every command of a batched response in order,
    missing count header = 1, default client sends no header.
  • HttpBatchedPollTest: end-to-end over real HTTP connectors, 500 messages in order with
    auto-acknowledge and transacted sessions, against a connector with wireFormat.maxFrameSize=8192
    (forces split batches), and an old client against the new broker.

Measurements

Simulated 20 ms per-request round trip, 200 messages, prefetch 100:

Consumer 1 command per GET batchedPoll=true
transacted, commit every 50 11.2 s (205 GETs) 0.77 s (8 GETs)
transacted, commit each message 38.1 s 33.2 s
auto-acknowledge 10.4 s 10.1 s

The gain shows up when commands are already queued, for example batched commits or acks.
Consumers that acknowledge every message let only one dispatch queue up at a time.

Open points

  1. When wireFormat.maxFrameSize is unset (unlimited by default), is prefetch alone an acceptable
    bound, or would you like a fallback size cap?
  2. Should batchedPoll default to true? It is compatible with old brokers and old clients.
  3. Backport to 6.4.x / 5.19.x? The change applies cleanly to the 6.3.x line.
  4. Website docs for batchedPoll: I'll send a separate PR to activemq-website once agreed.

Mensikovs Kirils added 2 commits December 1, 2026 08:51
The HTTP transport delivers broker-to-client commands through a long-poll GET
that returns exactly one command, so a client drains a backlog at one command
per network round trip no matter how many are already queued for it.

- Client: new transport option maxCommandsPerPoll (default 1). When greater
  than 1 the GET carries the header ActiveMQ-Max-Commands.
- Broker: HttpTunnelServlet keeps the existing blocking poll for the first
  command, then drains whatever is already queued, without waiting, up to the
  requested number, capped by the connector option http.maxCommandsPerPoll
  (default 100). The number sent is returned in ActiveMQ-Command-Count.
  Commands keep the existing length-prefixed framing, back to back.
- Either side alone behaves as before: an old client sends no header and gets
  one command; an old broker ignores the header and sends one command without
  a count header, which a new client reads as one.
Replace the fixed command count with limits the broker already has, as
suggested in review:

- Drop the client option maxCommandsPerPoll and the connector option
  http.maxCommandsPerPoll. The client now sends ActiveMQ-Batched-Poll: true
  when batchedPoll=true.
- The broker returns every command already queued for the client. The queue
  only holds what has been dispatched, so consumer prefetch bounds the count.
- The response is capped by the connector's existing wireFormat.maxFrameSize,
  previously only applied to POST. The first command is always sent, as
  before; a command that would exceed the limit goes back to the head of the
  queue, now a LinkedBlockingDeque, so order is kept.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant