There was a question on the MQ section on StackOverflow
I have a standalone multi threaded java application which listen messages from IBM MQ.
Current system take around 500ms for processing of 1 message after it read from queue and till it commit.
I want to know how many messages I can consume
- Concurrently:
- Max number of messages can be processed? or throttle limit
A good meaty performance question I thought. Let me break this into pieces.
Current system take around 500ms for processing of 1 message after it read from queue and till it commit.
Processing one messages and commit should take about 10 milliseconds or less( say 30 ms for a two phase commit). There is clearly something else going on. Fix this first.
- A long database call. This could be due to database locking, or a badly designed statement, for example a query which needs to access thousands or millions of rows.
- A request to a server far far away
- A file system with the speed of writing an illuminated letter to parchment
How many messages I can consume: Concurrently:
Take the worst case of using persistent messages, which require log IO during commit.
For one thread, processing multiple messages before doing a commit means the thread can do more work. Consider a get taking 1 millisecond, and a commit taking 10 ms. This is one message processed every 11 ms. If you did 50 gets – taking 50 ms and a commit taking 10 ms, this is 50 messages in 50 + 10 ms which equates to one message every 1.2 milliseconds almost 10 times faster. This is how channels can send messages efficiently. There is a “sweet spot” of messages per commit to give you maximum data processed per second. This depends on the message size, logging rates and other factors. For a 100MB message it is one message per commit. For 10KB messages, this may be 1000 messages per commit.
This may be selfish
This is clearly a great improvement, but possibly selfish. If the application logic is a get followed by a database insert, followed by a commit, then doing 50 gets, 50 inserts and a commit, will work much faster. The down side is that the database requests will keep locks until the commit. These locks may prevent other applications from accessing data, either the recently inserted records, page locks, or index locks. So overall MQ throughput goes up – but the business transaction suffers. You need to understand the database and find the optimum number of requests per commit for your business transaction.
How long before the data is visible?
Rather than have one thread process 1000 messages per commit (taking 1010 ms) you may want to have multiple threads processing 10 messages per commit – taking 20 ms. This means that the data in the database (or replies etc) are visible earlier. This may be important to your business transaction if you have to worry about response time.
Parallel threads
- Using more threads should improve throughput, unless this is delayed by external factors – such as database locks.
- One customer found one thread was optimum because there was no database delays.
How many messages I can consume: Max number of messages can be processed? or throttle limit
There are papers written on this but here is a one minute overview
As fast as the queue manager can process data
- The rate at which MQ can write its logs
- Keep queue data in memory – ( buffer pools on z/OS, queue buffer on midrange), so few messages on the queue.
Threads
- Having parallel threads gives you better throughput than one thread. You get overlapped writing to the log, the units of work are shorter in duration, you can get parallel IO.
- You may be limited by the network. Having multiple threads from an application means the network can be better utilized. One thread can be receiving data down the wire, while another thread is waiting in commit.
- You may be limited by where your programs run – eg short of CPU, or slow IO (for your System.out.println statements)
Application design
- You may get delays due to serialization if all thread are using the same queue.
- Remove the debug printf or System.out.println statements.
- Using a queue per business application is better than all applications sharing the same queue
- Using one reply to queue per web server may be better than a shared reply to queue – especially if you use Apache Camel.
- Use get first if possible. Avoid scans of the queues.
The short answer….
You should be able to get thousands of 1KB messages a second through your Java application when using multiple threads.
One thought on “Stackoverflow: What throughput can a standalone Java program achieve?”