MDB transaction batching allows several JMS messages to be processed in one container managed transaction. Batching amortizes the cost of transactions over multiple messages and when used appropriately, can reduce or even eliminate the throughput difference between 2PC and 1PC processing. See Transaction Batching of MDBs in Programming WebLogic Enterprise JavaBeans.
Using batching may require reducing the number of concurrent MDB instances. If too many MDB instances are available, messages may be processed in parallel rather than in a batch. See MDB Thread Management.
While batching generally increases throughput, it may also increase latency (the time it takes for an individual message to complete its MDB processing).
MDB Thread Management
Thread management for MDBs is described in terms of concurrency—the number of MDB instances that can be active at the same time. The following sections provide information on MDB concurrency:
The following section provides general information on selecting a concurrency strategy for your applications:
Every application is unique, select a concurrency strategy based on how your application performs in its environment.
In most situations, if the message stream has bursts of messages, using an unconstrained work manager with a high fair share is adequate. Once the messages in a burst are handled, the threads are returned to the self-tuning pool.
In most situations, if the message arrival rate is high and constant or if low latency is required, it makes sense to reserve threads for MDBs. You can reserve threads by either specifying a work manager with a min-threads-constraint or by using a custom execute queue.
If you migrate WebLogic Server 8.1 applications that have custom MDB execute queues, you can:
Convert the MDB execute queue to a custom work manager that has a configured max-threads-constraint parameter and a high fair share setting.
You must configure the max-threads-constraint parameter to override the default concurrency of 16.
In WebLogic Server 8.1, you could increase the size of the default execute queue knowing that a larger default pool means a larger maximum MDB concurrency. Default thread pool MDBs upgraded to WebLogic Server 9.0 will have a fixed maximum of 16. To achieve MDB concurrency numbers higher than 16, you will need to create a custom work manager or custom execute queue. See Table 10-1.
Thread Utilization When Using WebLogic Destinations
The following section provides information on how threads are allocated when WebLogic Server interoperates with WebLogic destinations.
Non-transactional WebLogic MDBs allocate threads from the thread-pool designated by the dispatch-policy as needed when there are new messages to be processed. If the MDB has successfully connected to its source destination, but there are no messages to be processed, then the MDB will use no threads.
Transactional WebLogic MDBs with transaction batching disabled work the same as non-transactional MDBs.
The behavior of transactional MDBs with transaction batching enabled depends on whether the MDB is listening on a topic or a queue:
MDBs listening on topics — Each deployed MDB uses a dedicated daemon polling thread that is created in Non-Pooled Threads thread group.
Token-based Message Polling for Transactional MDBs Listening on Queues
Transactional WebLogic MDBs use a synchronous polling mechanism to retrieve messages from JMS destinations if they are either: A) listening to non-WebLogic queues; or B) listening to a WebLogic queue and transaction batching is enabled. With synchronous polling, one or more WebLogic polling threads synchronously receive messages from the MDB’s source destination and then invoke the MDB application’s onMessage callback.
As of WebLogic 10.3, the polling mechanism changed to a token-based approach to provide better control of the concurrent poller thread count under changing message loads. In previous releases, the thread count ramp-up could be too gradual in certain use cases. Additionally, child pollers, once awoken, could not be ramped down and returned back to the pool for certain foreign JMS providers.
When a thread is returned to the thread pool with token-based polling, the thread’s internal JMS consumer is closed rather than cached. This assures that messages will not be implicitly pre-fetched by certain foreign JMS Providers while there is no polling thread servicing the consumer.
In addition, each MDB maintains a single token that provides permission for a given poller thread to create another thread.
On receipt of a message — A poller thread that already has the token or that is able to acquire the token because the token is not owned, wakes up an additional poller thread and gives the token to the new poller if the maximum concurrency has not yet been reached. If maximum concurrency has been reached, the poller thread simply releases the token (leaving it available to any other poller).
On finding an empty queue — A poller tries to acquire the token and if successful will try to poll the queue periodically. If it fails to acquire the token, it returns itself back to the pool. This ensures that with an empty queue, there is still at least one poller checking for messages.
Backwards Compatibility for WLS 10.0 and Earlier-style Polling
In WLS 10.0 and earlier, transactional MDBs with batching enabled created a dedicated polling thread for each deployed MDB. This polling thread was not allocated from the pool specified by dispatch-policy, it was an entirely new thread in addition to the all other threads running on the system. See Use Transaction Batching.
To override the token-based polling behavior and implement the WLS 10.0 and earlier behavior, you can either:
At the server level, set the weblogic.mdb.message.81StylePolling system property to True to override the token-based polling behavior.
At the MDB level, set the use81-style-polling element under message-driven-descriptor to override the token-based polling behavior.
When using foreign transactional MDBs with the WLS 8.1-style polling flag, some foreign vendors require a permanently allocated thread per concurrent MDB instance. These threads are drawn from the pool specified by dispatch-policy and are not returned to the pool until the MDB is undeployed. Since these threads are not shared, the MDB can starve other resources in the same pool. In this situation, you may need to increase the number of threads in the pool.
With the token-based polling approach for such foreign vendors, the thread’s internal JMS message consumer is closed rather than cached to assure that messages will not be reserved by the destination for the specific consumer.