kiril-me opened a new issue, #2902: URL: https://github.com/apache/activemq/issues/2902
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: a new transport option maxCommandsPerPoll (default 1, today's behaviour). When it is above 1, the GET carries the request header ActiveMQ-Max-Commands: <n>. Broker: HttpTunnelServlet.doGet keeps the existing blocking poll for the first command. Then, without waiting, it adds commands already in the queue (via non-blocking poll()), up to the requested number and capped by a new connector option http.maxCommandsPerPoll. The response header ActiveMQ-Command-Count: <k> says how many commands are in the body. Format: TextWireFormat.marshal already writes a length prefix before each command, so the body is simply k frames back to back. No new format. Order is unchanged: one queue, one reader thread, commands handed on in order. A ShutdownInfo taken 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 n commands per GET. Measurements Setup: the 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 no ResponseCorrelator. 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 per POST): worthwhile, but doPost reads 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.maxCommandsPerPoll default to batching enabled (proposed 100, because the client must opt in anyway) or to 1, so the broker operator must opt in too? Header names: ActiveMQ-Max-Commands and ActiveMQ-Command-Count, or something else? Branches: target main and backport to 6.4.x and 5.19.x? The change applies to 6.3.3 without conflicts. I have a patch with unit tests (servlet and client) and end-to-end tests (batched, transacted, old client against new broker), and I can open a PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information, visit: https://activemq.apache.org/contact
