How big is an MSMQ message really?


Just a quick note about how MSMQ reports message size.


If you look in the Computer Management snap-in you will see a column marked “size”. This is not the message size; it is instead the message BODY size. 


 


I have already populated the queue with 10 messages containing a 10-character payload in my example screenshot. As the 10 characters are in Unicode (double-byte), they take up 20 bytes instead of 10.


To get an idea of the actual message size, have a look in Performance Monitor:


 


As you can see, there are 10 messages taking up 2,440 bytes. So each message must be averaging 244 bytes – 20 bytes of which is the 10 character payload, 20-22 bytes for the label (again double-byte Unicode) and the rest is overhead.


To get an idea of what sort of things constitute this overhead you can look through the MSMQ API on MSDN or, more simply, have a look at what other column headings are available in Computer Management:



For example, I found after adding the various queue name lengths that both “recipient queue name length” and “destination queue format name length” were 44 bytes long (for the PUBLIC={GUID} queue name used by my application to send the messages).


If the actual message size is critical to your system then you could, if you really wanted to, track down and account for all the bytes in the message.


It is not possible to generalise about how big the overhead will be, though, without benchmarking it yourself with a wide range of representative messages.

Comments (2)

  1. peleg says:

    how do u get the message size?

  2. MSDNArchive says:

    Hi Peleg,

    I think getting the total message size (header + body) is possible but I’ve not seen an example of anyone doing it. There may be something in the .Net API that allows you to manipulate the raw message in this way.

    There a few problems with getting the message size though. The size of the message on the wire is not the same as that of the message in storage. This is because some properties are only necessary for ensuring delivery and are dropped after storage. Similarly, some properties have no relevance on the wire so only exist while in storage.

    Do you really need to know the message size? I assume this is so you can avoid reaching the 4MB limit.

    Cheers

    John Breakwell (MSFT)