[ActiveMQ Tuning] Prefetch Limit

Source: Internet
Author: User
Tags prefetch

Abstract: ActiveMQ optimizes client-side prefetch optimization restrictions

Original article: http://fusesource.com/docs/broker/5.4/tuning/GenTuning-Consumer-Prefetch.html

Overview: Figure 4.1 illustrates the behavior of Broker feedback sent to the client before waiting.

Figure 1.4. Consumer Prefetch Limit

 

 

If the client process is slow, the Broker will send new messages to the client before sending feedback to the client. If the client is still slow, messages that are not confirmed will continue to grow. In this case, the Broker may stop sending messages to consumers. When the unfed message reachesPrefetch limitWhen the number is set, the Broker stops sending new messages to the consumer. No message is received unless the consumer starts to give feedback.

Default Prefetch Limit (Default Prefetch Limit): different consumer types have different Default settings. The specific settings are as follows:

Queue consumer: 1000 by default

If you use a group of consumers to distribute the workload (one Queue corresponds to multiple consumers), you should set a smaller number. If a consumer is allowed to gather a large number of unconfirmed messages, other consumers will have nothing to do. In addition, if this consumer fails, a large number of messages cannot be processed until the consumer recovers.

Queue browser: 500 by default

Topic consumer: 32766 by default

The default value 32766 is the maximum value of the number short and the maximum value of the prefetch limit.

Durable topic subscriber: 100 by default

You can improve the performance by adding prefetch restrictions.

Optimizing prefetch limits (optimized prefetch limit): Normally, Optimizing Queue consumption and durable topic subscriber is a good idea.

  • Queue consumers-If your queue has only one consumer, you can set the prefetch limit to a very large value. However, if a queue has a group of consumers, you 'd better limit it to a relatively small number, such as 0 or 1.
  • Durable topic subscribers-Generally, increasing the number of prefetch restrictions improves performance. Try to increase to 1000.

How to set prefectch limits (How to set prefetch restrictions): You can set prefetch limits on the Broker or consumer. There are three ways to set the granularity. As follows:

  • Per broker.

  • Per connection factory.

  • Per destination.

Per broker: You can set the prefetch limit for all consumers connected to the Broker by setting the target policy of borker. To set the target policy, add sub-entries to the broker.destinationPolicy. Refer to the following:

<Broker...>

...
<DestinationPolicy>
<PolicyMap>
<PolicyEntries>
<PolicyEntry queue = "queue.>" queuePrefetch = "1"/>
<PolicyEntry topic = "topic.>" topicPrefetch = "1000"/>
</PolicyEntries>
</PolicyMap>
</DestinationPolicy>
...
</Broker>

In the previous example, allqueueThe prefetch limit of the named queue is set to 1. (> it is a wildcard that is used to match one or more named segments ). All starttopicSet the prefetch limit of the topic to 1000.

The followingpolicyEntryAttributes are also used to set prefetch restrictions:

queuePrefetch: Prefetch limit of the queue consumer.

queueBrowserPrefetch: Specifies the prefetch limit of the queue viewer.

topicPrefetch: Prefetch limit of the topic consumer.

durableTopicPrefetch: Specify the prefetch limit of the durable topic subscriber.

Per connection factory: On the consumer side, you canActiveMQConnectionFactoryTo set the prefetch limit for a Connection factory instance. The Code is as follows:

// Java

ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory ();

Properties props = new Properties ();
Props. setProperty ("prefetchPolicy. queuePrefetch", "1000 ");
Props. setProperty ("prefetchPolicy. queueBrowserPrefetch", "500 ");
Props. setProperty ("prefetchPolicy. durableTopicPrefetch", "100 ");
Props. setProperty ("prefetchPolicy. topicPrefetch", "32766 ");

Factory. setProperties (props );

Per destination: the best granularity. You can set the prefetch limit for each target when creating a consumer. Consume queue,TEST.QUEUE, Specify the prefetch limit to 10. CreateMessageConsumerThe instance code is as follows:

// Java

Queue queue =
New ActiveMQQueue ("TEST. QUEUE? Consumer. prefetchSize = 10 ");

MessageConsumer consumer = session. createConsumer (queue );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.