I have a client-server application that utilises MSMQ and NServiceBus for messaging. During some recent testing, clients were left inactive for some time and unexpected behaviour of MSMQ was discovered:
- MSMQ has a default number of threads that it uses to process queues
(set in registry as QMThreadNo). When queues are left in a dormant
state for an extended period of time, they accumulate a large number
of messages. These large queues hold onto the limited number of
threads that MSMQ has for longer than usual and therefore does takes
longer to process the queues that are actually active.- It is possible to set the registry entry to a higher thread count.
- Clients that are not sending/receiving messages for a set period of
time (set in registry as the CleanupInterval) will change to an
“Inactive” state and eventually their queues will be deleted until a
message is sent from that client, forcing the recreation of the
queues.- The CleanupInterval can be changed from its default of 5 minutes to a much longer amount of time.
Has anyone encountered these issues before? And if so, what possible solutions are there?
You need to differentiate between Outgoing Queues or destination Queues.
MSMQ has a thread pool for outgoing queues. MSMQ will try and connect the outgoing queue to the destination and deliver the messages. If you have, for example, 1,000 outgoing queues then it will take some time for MSMQ to cycle through all of them.
This has nothing to do with destination queues.
I don’t quite understand how the number of messages in an outgoing queue will affect thread usage. There will only be one thread in use on a particular queue at any one time.
An active queue has a thread – as otherwise it wouldn’t be active. I assume we are talking about the Status of the queue in Computer Management here.
Again, this is Outgoing queues only. Outgoing queues are dynamically created by MSMQ on demand. They are deleted, if empty, after the CleanupInterval. This is perfectly normal and how MSMQ frees up resources.
Like any product, MSMQ may need optimisation to meet your needs. If you want to change the registry values, go ahead.
Cheers
John Breakwell