Author |
Message
|
yalmasri |
Posted: Sat Jul 19, 2008 6:54 am Post subject: Pooling Queue Objects |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
Hi,
I'm wondering if there is any problem caching the MQQueue objects returned from MQQueueManager.accessQueue(...) and using them in a multi-threaded environment, so instead of each time retrieving the queueManager from the pool, accessing the queue, then getting or putting any messages, I'd pick up the queue object itself and get or put messages on it straight ahead.
Is there anyone who discourages this practice? Any precautions for this like simultaneous access to same queue object or sharing it between threads? Of course any number of MQQueue objects will be retrieved from an equivalent number of different MQQueueManager objects. |
|
Back to top |
|
 |
sridhsri |
Posted: Sat Jul 19, 2008 6:59 am Post subject: |
|
|
Master
Joined: 19 Jun 2008 Posts: 297
|
It would depend on how that queue was opened. If the queue was opened in EXCLUSIVE mode, then other threads wont be able to access it. |
|
Back to top |
|
 |
yalmasri |
Posted: Sat Jul 19, 2008 7:22 am Post subject: |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
So if in shared mode, what is the difference between saying:
new MQQueueManager("QM_1").accessQueue(...).get(MQMessage,corr_1);
new MQQueueManager("QM_2").accessQueue(...).get(MQMessage,corr_2);
and
MQQueue q = new MQQueueManager("QM").accessQueue(...);
Thread_1.q.get(MQMessage,corr_1);
Thread_2.q.get(MQMessage,corr_2);
Is there any performance gain for example? |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Jul 19, 2008 12:34 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
yalmasri wrote: |
So if in shared mode, what is the difference between saying:
new MQQueueManager("QM_1").accessQueue(...).get(MQMessage,corr_1);
new MQQueueManager("QM_2").accessQueue(...).get(MQMessage,corr_2);
and
MQQueue q = new MQQueueManager("QM").accessQueue(...);
Thread_1.q.get(MQMessage,corr_1);
Thread_2.q.get(MQMessage,corr_2);
Is there any performance gain for example? |
There is a big difference.
While retrieving and serving up a message your connection will be synchronized...
So having multiple threads read from the same queue on the same connection will only speed up by the time spent in processing the message. If you use a connection by thread you engineer true parallelism and not a single threaded process with a fork...
Having multiple threads read from the same connection would be like having a single thread read from the connection and spawning off a new one to process the message once retrieved...
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
yalmasri |
Posted: Sat Jul 19, 2008 10:16 pm Post subject: |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
And what's your advice fjb_saper about pooling queue objects? |
|
Back to top |
|
 |
fjb_saper |
Posted: Sun Jul 20, 2008 2:57 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
yalmasri wrote: |
And what's your advice fjb_saper about pooling queue objects? |
Not necessary or you would have a pool delivered in the MQ package.
Pool the connections.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
yalmasri |
Posted: Mon Jul 21, 2008 10:54 pm Post subject: |
|
|
Centurion
Joined: 18 Jun 2008 Posts: 110
|
Any particular reason? I mean on the technical level rather than logical  |
|
Back to top |
|
 |
|