简体   繁体   中英

Message Header Size for JMS producer in ActiveMq v5.10

I was trying to use Message Size related stats
(Minimum message size, Maximum message size, Average message size, Total message size by using

DestinationStatistics .getMessages().getCount()

) provided in ActiveMQ v5.10 and found that header size is 1028 bytes (send message of different sizes and size returned by API is 1028 bytes more). I am not able to understand why size is this.

Is it prefixed? Is there anyway to see what constitute header.

Thanks

EDIT:
So basically producer is sending a text message of 1024 bytes (chars) using java code on a queue to broker which is received by consumer listening onto that queue. I am logging message sizes using the above said API and I found that message size reported is 2052 bytes and not 1024 bytes.

The size you are seeing is an approximation of total message size. The broker will not track exact messages sizes as parts of the message are unmarshaled on the Broker prior to being dispatched into the core where these statistics are updated. The additional byte overhead value of 1024 is added to account for bytes added when the message is encoded and sent on the wire. There is no way to separate from those statistics what the size of the message properties was vs the size of the body etc, this number is just a best guess at total encoded message size.

Turn on the trace-level logging for ActiveMQ in your client application to see more details about sent messages. The messages can and will contain lots of "metadata" the brokers and clients use, for example sending a simple test-message within our own server software shows the following:

[scheduler-1] TRACE org.apache.activemq.ActiveMQSession - ID:esaj-HP-59250-1410162276798-1:1:36 sending message: ActiveMQTextMessage {commandId = 0, responseRequired = false, messageId = ID:esaj-HP-59250-1410162276798-1:1:36:1:2, originalDestination = null, originalTransactionId = null, producerId = ID:esaj-HP-59250-1410162276798-1:1:36:1, destination = topic://server.diagnostics, transactionId = null, expiration = 1410162336586, timestamp = 1410162324586, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = null, persistent = false, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = { ** OMITTED, OUR CUSTOM PROPS ** }, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = { ** THE ACTUAL DATA ** }}

This was with ActiveMQ 5.9, but as you can see, there's lots of header data that ActiveMQ produces on its own. As for how to actually get rid of it, I'm not sure, I'm not really an ActiveMQ-specialist, but I'd say a kilobyte of header data seems just "normal" for ActiveMQ.

Edit : I took a look into our message brokers, and all queues and topics show average message sizes above 1024 bytes, which lead me to delve a bit into the ActiveMQ (5.9) source. I found this in org.apache.activemq.command.Message :

/**
 * The default minimum amount of memory a message is assumed to use
 */
public static final int DEFAULT_MINIMUM_MESSAGE_SIZE = 1024;

//Omitted other stuff...

@Override
public int getSize() {
    int minimumMessageSize = getMinimumMessageSize();
    if (size < minimumMessageSize || size == 0) {
        size = minimumMessageSize;
        if (marshalledProperties != null) {
            size += marshalledProperties.getLength();
        }
        if (content != null) {
            size += content.getLength();
        }
    }
    return size;
}

protected int getMinimumMessageSize() {
    int result = DEFAULT_MINIMUM_MESSAGE_SIZE;
    //let destination override
    MessageDestination dest = regionDestination;
    if (dest != null) {
        result=dest.getMinimumMessageSize();
    }
    return result;
}

And getSize() is used in many places, like MessageQueue , ActiveMQSession etc. I didn't delve much deeper, but it looks like at least 1024 bytes (1 kilobyte) is either reserved or at least assumed in statistics for each message. The statistics seem to be gathered in Queue - and Topic -classes, and uses the value returned by getSize() , here's for example the beginning of Queue.messageSent:

final void messageSent(final ConnectionContext context, final Message msg) throws Exception {
    destinationStatistics.getEnqueues().increment();
    destinationStatistics.getMessages().increment();
    destinationStatistics.getMessageSize().addSize(msg.getSize());

I don't know whether 1024 bytes is actually transmitted over the wire when sending an empty message, but at least the statistics seem to assume so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM