简体   繁体   English

ActiveMQ实际上不遵守内存限制

[英]ActiveMQ does not actually respect memory limits

I'm trying to set up ActiveMQ to use memory limits and producer flow control so that I don't see the hang behaviour that can be seen when you try to send a message when there is insufficient memory. 我试图将ActiveMQ设置为使用内存限制和生产者流控制,以使我看不到当内存不足时尝试发送消息时可以看到的挂起行为。 I have followed the documentation at Producer Flow Control , My producer blocks and Connection Configuration URI with little luck. 我很幸运地关注了Producer Flow ControlMy producer块Connection Configuration URI上的文档。

The problem I am running into is that these settings don't actually appear to be properly honored. 我遇到的问题是这些设置实际上似乎并没有被正确接受。

My ActiveMQ broker is set up like so in my Spring config (I have sanitized this slightly so may not be 100% valid Spring config): 我的ActiveMQ代理的设置如下所示(在我的Spring配置中)(我已经对此做了一些消毒,因此可能不是100%有效的Spring配置):

<bean id="broker" class="org.apache.activemq.broker.BrokerService"
    init-method="start">
    <property name="brokerName" value="broker" />
    <property name="persistent" value="false" />
    <property name="useJmx" value="true" />
    <property name="managementContext" ref="mgmtContext" />
    <property name="transportConnectorURIs">
        <list>
            tcp://localhost:1234?jms.prefetchPolicy.queuePrefetch=0&jms.useAsyncSend=false&jms.alwaysSyncSend=true
        </list>
    </property>
        <property name="destinations">
            <list>
                <bean class="org.apache.activemq.command.ActiveMQQueue">
                    <property name="physicalName" value="requests"></property>
                </bean>
                <bean class="org.apache.activemq.command.ActiveMQQueue">
                    <property name="physicalName" value="responses"></property>
                </bean>
            </list>
    </property>
</bean>

And then in one of my codes init methods I set the following: 然后在我的代码init方法之一中设置以下内容:

broker.getSystemUsage().setSendFailIfNoSpace(true);
broker.getSystemUsage().setSendFailIfNoSpaceAfterTimeout(5000);

// Limit memory usage to 10MB
broker.getSystemUsage().getMemoryUsage().setLimit(10 * 1024 * 1024);

Yet when I run my code I still see things in my logs like the following: 但是,当我运行代码时,仍然在日志中看到如下内容:

2013-Mar-14 14:47:31.538 GMT-06:00 DEBUG [ActiveMQ Transport: tcp:///127.0.0.1:45846@18086] [org.apache.activemq.usage.Usage:fireEvent] [Usage.java:245] [] [] [] - Main:memory: usage change from: 5640% of available memory, to: 0% of available memory

So ActiveMQ appears to be blatantly flouting the set memory limit. 因此ActiveMQ似乎公然违反了设置的内存限制。

I still see the blocking behavior that can occur if you put a sufficiently large message into the queue and even OOM errors if I put a really large message into the queue. 我仍然看到如果将足够大的消息放入队列中,甚至如果我将非常大的消息放入队列中,都可能发生OOM错误,从而可能发生阻塞行为。

How do I reliably configure ActiveMQ to limit its memory usage. 如何可靠地配置ActiveMQ以限制其内存使用量。

Ha you tried configure your broker directly with the xml file? 哈,您尝试直接使用xml文件配置代理吗? You can do that like this (extract from the official Java example ): 您可以这样操作(摘自官方Java示例 ):

BrokerService broker = BrokerFactory.createBroker(configUrl); BrokerService经纪人= BrokerFactory.createBroker(configUrl);

I'll try getting a running Spring example later 稍后我将尝试获取正在运行的Spring示例

I have tried that but I could not resolved that what i am seeking but I finally got below link it has complete information 我已经尝试过了,但是我无法解决我要寻找的东西,但是我终于在下面的链接中获得了完整的信息

http://blogs.sourceallies.com/2014/10/activemq-memory-tuning/ http://blogs.sourceallies.com/2014/10/activemq-memory-tuning/

Thanks to above thread, I got solution. 由于上述线程,我得到了解决方案。 Above thread has good amount of information. 上面的线程有很多信息。 I have change the activemq.xml as follows 我已如下更改activemq.xml

<systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="2048 mb"/>
                    <!--Earlier it use to be 
                    <memoryUsage limit="64 mb"/>
                    -->
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="100 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="50 gb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

For anyone looking how to manage programmatically the broker limits, here is an example: 对于希望通过编程方式管理经纪人限额的任何人,下面是一个示例:

    @Bean
    public BrokerService broker()
            throws Exception {
        final BrokerService broker = new BrokerService();
        broker.addConnector("tcp://localhost:61616");
        broker.addConnector("vm://localhost");
        broker.setPersistent(false);
        broker.getConsumerSystemUsage().getMemoryUsage().setLimit(100 * 1024);
        broker.getConsumerSystemUsage().getStoreUsage().setLimit(1024 * 1024);
        broker.getConsumerSystemUsage().getTempUsage().setLimit(100 * 1024);
        return broker;
    }

Thanks to this post for the starting point: How to set ActiveMQ port in Spring Boot? 感谢这篇文章的起点: 如何在Spring Boot中设置ActiveMQ端口?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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