Startup scripts to set the JVM's memory
If "%activemq_opts%" = = "" Set Activemq_opts=-xms1g-xmx1g-djava.util.logging.config.file=logging.properties
The amount of system memory and disk space used in the broker configuration
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryusagelimit= "MB"/>
</memoryUsage>
<storeUsage>
<storeusagelimit= "GB"/>
</storeUsage>
<tempUsage>
<tempusagelimit= "GB"/>
</tempUsage>
</systemUsage>
</systemUsage>
In the case of embedded (embedded) Use, you can add a systemusage to the Brokerservice. The memoryusage configured here must be smaller than the number set in the JVM.
5.9.0 version, if the set MEMORYUSAGELIMIT is greater than the actual available Java heap size value, such as the default startup xmx=1g, then the actual Java heap size is approximately 910M,
The broker starts with a log.error prompt to set a memory error, and then enforces the actual Java heap size* 70% = 637M as Memoryusagelimit.
splitsystemusageforproducersconsumers The problem of slow consumption and even inability to consume
In fact, the broker can also individually configure the producersystemusage used by producers and the consumersystemusage used by consumers, in the same format as Systeusage.
By default, Producersystemusage and Consumersystemusage are not configured, and both producers and consumers use Systemusage.
This could be because the producer thread runs out of memory, causing the consumer to slow down or even consume the thread. In this case, the number of machines and consumers added to the consumer may not increase the speed of consumption.
The solution is:
Set splitsystemusageforproducersconsumers= "True" on the broker, allowing both producer and consumer threads to use each memory.
The default is producer thread Memory: consumer thread memory = 6:4.
You can also set up half of the producer thread memory and consumer thread memory by the following two parameters:
Producersystemusageportion = 50
Consumersystemusageportion = 50
Producer Flow Control
From the 5.x version, you can set up a separate flow control for each producer. Flow control is simply about controlling the behavior of the producer under the memory usage limit. Of course, the purpose of the flow control is to prevent the problem of MQ bursting when the production speed is greater than the consumption speed when using ACTIVEMQ as memory MQ.
In two cases:
1. Send the message synchronously (Useasynsend is false): At this point, the restrictions in Policyentry in Destinationpolicy are used, for example:
<destinationPolicy>
<policyMap>
<policyEntries>
<policyentry queue= "QueueA" producerflowcontrol= "true" memorylimit= "1MB" >
<pendingQueuePolicy>
<vmQueueCursor/>
</pendingQueuePolicy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
Limit non-persistence when the memory usage of the QueueA is 1MB, when this memory usage is reached, it blocks producer until there is free memory to allow producer to send messages.
You can also control client exceptions and wait times by setting sendfailifnospace= "true" or sendfailifnospaceaftertimeout= "3000" on the Systemusage configuration.
When sending asynchronously, because the producer is not blocked,
Can be passed connctionfactory.setproducerwindowsize (1024000);
To control the maximum amount of data (in bytes) that the producer can send before the broker confirms that the message was received.
Consumer Flow Control
Consumer, in general, the faster the better, the smaller the broker backlog the better.
But given the transactional and client-side acknowledgements, if a consumer gets a lot of messages at a time and does not confirm, this causes the transaction context to become larger, and the broker-side "half-consumed" data becomes more So ACTIVEMQ has a prefetchsize parameter to control the number of records that can be pre-fetched in an unconfirmed situation.
The default is as follows:
Persistent queue:1000 Bar
Non-persistent queue:1000 bar
Persistent topic:100 Bar
Non-persistent topic: unlimited
Prefetchsize can be set in 3 mode
1, tcp://localhost:61616?jms.prefetchpolicy.all=50
2, Tcp://localhost:61616?jms.prefetchpolicy.queueprefetch=1
3. Queue = new Activemqqueue ("TEST. Queue?consumer.prefetchsize=10 ");