4 Replies Latest reply on Aug 24, 2010 7:26 PM by clebert.suconic

    message size

    oferiko

      Hello all,

      What is the best way to estimate the size of a message?

      I know how many bytes will be used by my parameters of the message, but i don't know the overhead of the message itself, especially if using a JMS message.

       

      Any easy way to calculate that, so that i can configure my queue size accordingly? (without the need to use a profiler)

       

      thanks

        • 1. Re: message size
          clebert.suconic

          We have a test where we allocate references and messages.. and calculate the offset of each message

           

          We have calculated that each message reference will take 48 bytes if 64 bits or 32  bytes if 32 bits

           

           

           

             static
             {
                // This is an estimate of how much memory a ServerMessageImpl takes up, exclusing body and properties
                // Note, it is only an estimate, it's not possible to be entirely sure with Java
                // This figure is calculated using the test utilities in org.hornetq.tests.unit.util.sizeof
                // The value is somewhat higher on 64 bit architectures, probably due to different alignment
                if (MemorySize.is64bitArch())
                {
                   memoryOffset = 48;
                }
                else
                {
                   memoryOffset = 32;
                }
             }

           

           

           

           

          As for the message body itself, the calculation is done at ServreMessageImpl::getMemoryEstimate()

           

           

           

             public int getMemoryEstimate()

             {

                if (memoryEstimate == -1)

                {

                   memoryEstimate = ServerMessageImpl.memoryOffset + buffer.capacity() + properties.getMemoryOffset();

                }

           

                return memoryEstimate;

             }

          While memoryOffset for the message:
             static
             {
                // This is an estimate of how much memory a ServerMessageImpl takes up, exclusing body and properties
                // Note, it is only an estimate, it's not possible to be entirely sure with Java
                // This figure is calculated using the test utilities in org.hornetq.tests.unit.util.sizeof
                // The value is somewhat higher on 64 bit architectures, probably due to different alignment
                if (MemorySize.is64bitArch())
                {
                   memoryOffset = 352;
                }
                else
                {
                   memoryOffset = 232;
                }
             }

           

           

          We also calculate the offset of properties:

           

          We basically get the encodeSize of the properties and add a factor:

           

          size + 2 * DataConstants.SIZE_INT * properties.size()

           

           

           

           

          So, the size of the message is spread between the message itself + message references + properties size.

           

          This is of course an estimate.. .and we always welcome better estimates when someone finds them.

          • 2. Re: message size
            clebert.suconic

            Also, there's currently a bug that messages are using twice the size of their bodies on the server. I will see if I can fix it by 2.1.4. (2.1.3 will be a minor release with 1 or 2 fixes only)

            • 3. Re: message size
              oferiko

              i'll try to run the MemorySizeTest on my messages to get an estimation,

              thanks

              • 4. Re: message size
                clebert.suconic

                you should get approximate figures for Messages...

                 

                you may want to find out other objects.. like Consumers, Sessions... etc..