3

I'm using NServiceBus 3.3.8 with MSMQ under Windows 7. Currently the sending and receiving is working fine for both recoverable and express messages. However, I noticed that the MSMQ storage area is not cleaned up after the messages are consumed by the reader. This is causing me to cleanup the MSMQ storage manually when it reaches the maximum allowed queue size.

I tried decreasing the MessageCleanupInterval in registry and restarting MSMQ service, but still I don't see the messages are removed. When examined the pxxxxxx.mq files in storage folder, those contained both recoverable and express messages that I sent.

Has anybody got a clue on the reason for this message accumulating? And is there a way to prevent it with some configurations in MSMQ/NServiceBus?

Nalin
  • 93
  • 1
  • 7
  • Is this at all related to - http://stackoverflow.com/questions/1561063/msmq-cannot-delete-or-purge-a-queue ?? – Leptonator Sep 30 '13 at 03:22
  • No, this is not related to access rights. Just on increasing of the size of MSMQ storage area. – Nalin Sep 30 '13 at 03:25

1 Answers1

2

Empty storage files are deleted after 6 hours. This is for performance reasons - it is quicker for MSMQ to re-use an existing file then to create a new one.

If you open a P*.MQ file, you will indeed see data from previous messages. This is exactly the same as if you analysed any random sector of a hard disk. If a message has been processed, the storage area is flagged as free (in the corresponding L*.MQ file) so it can be overwritten by a future message. There is no gain from clearing storage space after each message has been read.

Storage files will hang around if they contain just a single message. There is no defragmentation to compact usage of storage files. If a file does not get purged after the clean-up interval or a restart then it is not empty. Check the MSMQ performance counters to see if the system as a whole (rather then just the queue you're interested in) has any messages lying around.

"However, I noticed that the MSMQ storage area is not cleaned up after the messages are consumed by the reader. This is causing me to clean-up the MSMQ storage manually when it reaches the maximum allowed queue size."

This is incorrect. If you delete storage files and the quota is then no longer reached, you must have deleted real messages to free up space. Empty storage files have zero impact on your message quota.

John Breakwell
  • 4,667
  • 20
  • 25
  • Thanks John. The problem was old messages were not cleaned after they were processed (after 6 hours). This caused the _System.Messaging.MessageQueueException: Insufficient resources to perform operation_ error as the storage area was full after few days. – Nalin Oct 01 '13 at 00:22
  • How are you processing messages? Are they received from the queue or just peeked? If you receive a message, it will be removed from the queue and no longer count towards any quotas. The 6 hours you refer to is for clearing up empty storage files. If they weren't cleared up then they weren't empty. – John Breakwell Oct 01 '13 at 18:54
  • 1
    I receive messages (through NServiceBus handlers) and see those get removed from queues after being processed. Even-though all queues get empty after processing messages, the MQ files sit forever in the storage area. None of the MQ files is empty. – Nalin Oct 02 '13 at 04:08
  • 1
    As I mentioned in my answer, the MQ files will never be empty of data as the space used by processed messages is just marked as free to be reused. The files can, though, be empty of messages. There is no value in looking inside an MQ file to solve this sort of problem. There are a number of queues in addition to those used by NSB where messages can reside. Check "MSMQ Service object - Total Messages in All Queues" in Performance Monitor to ensure your system is REALLY empty. – John Breakwell Oct 02 '13 at 20:29
  • Thanks a lot. With the performance counter you mentioned, I figured out that some messages (_Express_ messages with _Time to be Received_ 1 minute) are never processed when the message reader service is down for a while. When reader service is started back, it processes all other messages but the expired Express messages with 1 minute Time to Receive. So above performance counter shows that the system as a whole is not empty. Also there were no _R*.MQ_ files created for express messages and those messages also were in the _P*.MQ_ files. What is the reason for this behavior? – Nalin Oct 03 '13 at 06:22
  • 1
    Which queue were these expired messages in? DLQ? – John Breakwell Oct 05 '13 at 16:48
  • Yes, It was the Transnational DLQ which did not get attention at all. Now everything seems clear. – Nalin Oct 06 '13 at 10:19