ActiveMq优化

最近在研究ActiveMq,期间也遇到过很多问题,做了一些总结。

连接数配置

修改activemq.xml文件中maximumConnections参数值,默认最大连接为1000

1
2
3
4
5
6
7
8
9

<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=100000&amp;wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
</transportConnectors>

如果超出最大连接限制,会提示以下错误!

1
2
3
4
5
org.apache.activemq.transport.tcp.ExceededMaximumConnectionsException: Exceeded the maximum number of allowed client connections. See the 'maximumConnections' property on the TCP transport configuration URI in the ActiveMQ configuration file (e.g., activemq.xml)
at org.apache.activemq.transport.tcp.TcpTransportServer.doHandleSocket(TcpTransportServer.java:582)[activemq-client-5.15.6.jar:5.15.6]
at org.apache.activemq.transport.tcp.TcpTransportServer.handleSocket(TcpTransportServer.java:571)[activemq-client-5.15.6.jar:5.15.6]
at org.apache.activemq.transport.tcp.TcpTransportServer$1.run(TcpTransportServer.java:497)[activemq-client-5.15.6.jar:5.15.6]
at java.lang.Thread.run(Thread.java:748)[:1.8.0_181]

JVM虚拟机参数配置

当连接比较大,超过1万个长连接以上,很容易出现内存故障,导致MQ不可用,可以通过指定JVM参数解决。

修改bin目录配置文件env

1
ACTIVEMQ_OPTS_MEMORY="-Xms64M -Xmx1G"

大并发会出现以下异常,可以通过以上解决:

1
java.lang.OutOfMemoryError: GC overhead limit exceeded