MSMQ writes data to storage in 4 kilobyte chunks.

Saw a question on the MSMQ newsgroups the other day where someone had noticed that tiny MSMQ messages were causing the same amount of disk activity regardless of size and asked to know why.

The reason is that MSMQ messages won't be written to disk in the same way you would, for examples, update a record in an SQL database or create a document. 

Instead, MSMQ uses Memory Mapped Files (MMF) to store messages and therefore the operating system's paging mechanism. When a message arrives, it is written to memory first and the pages it occupies are marked as "dirty". These pages are then paged from memory to disk to update the MMF.

According to this KnowledgeBase article:

RAM, Virtual Memory, Pagefile and all that stuff

each page is 4 kilobytes. So each message generates disk activity in multipes of 4kb, regardless of actual size - 100 byte messages will write 4,096 bytes to disk, as will 4,000 byte messages; a 5,000 byte message will require two pages (8kb); and so on.

This isn't necessarily ideal for large volumes of tiny messages as the actual throughput of messages drops short of what the disk can handle. To improve this, you would need to somehow change the page size used by Windows. Personally that sounds a Very Bad Thing as there will be a huge number of applications out there that assume the page size is fixed at 4kb.

[[Note - Windows on ia64 uses 8kb pages]]

So, if you can't tweak the paging mechanism, have a look at the other aspects of the system:

  1. Consolidate data in your sending application to send fewer, larger messages
  2. Add a disk on a dedicated disk controller just for MSMQ to use; for transactional messaging, add up to three extra physical disks.