jms制作人与春天的表现 [英] jms producer performance with spring
问题描述
我基于spring,jms和activemq创建了一个简单的生产者消费者模拟,
我试图从双方,生产者和消费者那里获得高性能,
i created a simple producer consumer simulation based on spring, jms and activemq, i'm trying to reach high performance from both sides, producers and consumers,
连接设置:
<tx:annotation-driven />
<bean id="transactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="connectionFactory" />
</bean>
<amq:connectionFactory id="amqConnectionFactory" brokerURL="failover:(tcp://${broker.url}:61616)" />
<bean id="connectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="amqConnectionFactory" />
</bean>
<amq:queue id="queue" physicalName="queue" />
<beans:bean id="jsonMessageConverter" class="XXXXX.converter.JsonMessageConverter" />
消费者设置:
<jms:listener-container concurrency="10"
acknowledge="auto" prefetch="1" message-converter="jsonMessageConverter" transaction-manager="transactionManager"
>
<jms:listener id="queueListener_1" destination="ooIntegrationQueue"
ref="myMessageListenerAdapter" />
</jms:listener-container>
<beans:bean id="myMessageListenerAdapter"
class="org.springframework.jms.listener.adapter.MessageListenerAdapter" >
<beans:property name="delegate" ref="consumer"/>
</beans:bean>
<beans:bean id="consumer" class="XXX.ConsumerImpl"/>
制作人设置:
<beans:bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"
p:connectionFactory-ref="connectionFactory" p:messageConverter-ref="jsonMessageConverter"
p:defaultDestination-ref="ooIntegrationQueue" p:sessionTransacted="true" />
从消费者开始,我设法每秒消耗大约25条消息,这非常慢,我发现瓶颈是因为我正在使用交易,在谷歌搜索后获得
,并且使用配置,我发现自动装配DefaultMessageListenerContainer并将cachelevel更改为
starting with the consumer, i managed to consume about 25 messages per second, which is extremely slow, i discovered the bottleneck to be the fact that i am using transactions, after googling for a bit, and playing with the configs, i found out that after autowiring the DefaultMessageListenerContainer and changing the cachelevel to
listenerContainer.setCacheLevelName("CACHE_SESSION")
我的性能增加到每秒约1500条消息,同时仍有交易。
my performance increases to about 1500 messages per second while still having transactions.
我的问题是现在我的问题是生产商仍然停留在每秒约25次操作,
我的生产者测试很简单:
my problem is now with the producer which is still stuck at about 25 operations per sec, my producer test is simple :
int numOfMessages = getNumberOfMessages();
double startTime = System.currentTimeMillis();
for (int i = 1; i <= numOfMessages; i++) {
jmsTemplate.convertAndSend("HelloWorld" + i);
}
double endTime = System.currentTimeMillis();
double totalTime=(endTime-startTime)/1000;
System.out.println("Time - "+totalTime+" seconds");
System.out.println("EPS - "+numOfMessages/totalTime);
我想知道如何与制作人达成类似的演出,因为它现在已经成为整个系统的瓶颈。
i'm wondering how to reach similiar performances with the producer, since it now bottlenecks the entire system.
推荐答案
很抱歉,如果这个答案来得太晚,可以帮助原帖。我最近调查了 JmsTemplate
的性能。即使使用相同的传递和确认模式,本机 JMS
代码似乎比 JmsTemplate
快得多。问题原来是 ActiveMQ
通常默认为异步发送,但是当你使用 JmsTemplate
时它会使用同步发送。这大大降低了性能。您可以将 ActiveMQConnectionFactory
的 useAsyncSend
属性设置为 true
to强制异步发送。更多细节: JmsTemplate不是邪恶的
Sorry if this answer comes to late to help the original poster. I recently investigated JmsTemplate
performance. Even with the same delivery and acknowledgment modes, native JMS
code seemed much faster than JmsTemplate
. The problem turned out to be that ActiveMQ
normally defaults to async sending, but when you use JmsTemplate
it instead uses sync sending. This dramatically reduces performance. You can set ActiveMQConnectionFactory
's useAsyncSend
property to true
to force async sending. More details here: JmsTemplate is not evil
这篇关于jms制作人与春天的表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!