Sending message to JMS endpoint is slow every x messages

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Sending message to JMS endpoint is slow every x messages

iasonp
Hi,

if I send a message to an ActiveMQ broker directly (without camel) this is extremly fast (<1ms). When sending messages in a camel route using the JMS endpoint it is extremly slow (> 1 sec) every x messages.
Here is an example output of the provided test:

sending took 81ms
sending took 1081ms
sending took 80ms
sending took 86ms
sending took 80ms
sending took 70ms
sending took 70ms
sending took 1062ms
sending took 61ms
sending took 65ms
sending took 59ms
sending took 61ms
sending took 52ms
sending took 50ms
sending took 53ms
sending took 51ms
sending took 54ms
sending took 54ms
sending took 1049ms
sending took 1051ms
sending took 49ms
sending took 53ms
sending took 1053ms
sending took 49ms
sending took 48ms
sending took 49ms
sending took 51ms
sending took 47ms
sending took 48ms
sending took 49ms

Do you have any idea what is going on here? Is it maybe a configuration issue? Below you can find the JUnit test and the activemq.xml

Best regards

MyTest:

@Before
  public void before() throws Exception {
    final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?brokerConfig=xbean:activemq.xml&marshal=false");
    factory.setUseAsyncSend(true);

    context = new DefaultCamelContext();
    context.addComponent("jms", JmsComponent.jmsComponent(factory));
    context.addRoutes(new RouteBuilder() {
      public void configure() {
        from("direct:start")
            .process(new Processor() {
              @Override
              public void process(final Exchange exchange) throws Exception {
                exchange.getIn().setHeader("timer", Stopwatch.createStarted());
              }
            })
        .to(createJmsEndpoint(context))
        .process(new Processor() {
          @Override
          public void process(final Exchange exchange) throws Exception {
            System.out.println("sending took " + ((Stopwatch) exchange.getIn().getHeader("timer")).elapsed(TimeUnit.MILLISECONDS) + "ms");
          }
        });
      }
    });
    context.start();
  }

  private Endpoint createJmsEndpoint(CamelContext camelContext) {
    try {
      final String endpointUri = "jms:topic:EVENTBUS-0001?testConnectionOnStartup=true";
      return camelContext.getComponent("jms").createEndpoint(endpointUri);
    } catch (Exception e) {
      throw new CepCamelException(e);
    }
  }


  @Test
  public void test() {
    final ProducerTemplate producerTemplate = context.createProducerTemplate();
    String text = "Test";
    for (int i = 0; i < 100000; i++) {
      producerTemplate.sendBody("direct:start", text);
    }
  }


activemq.xml:

<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:amq="http://activemq.apache.org/schema/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
  <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" persistent="false" >
    <managementContext>
      <managementContext createConnector="false"/>
    </managementContext>

    <systemUsage>
      <systemUsage>
        <memoryUsage>
          <memoryUsage limit="100 mb"/>
        </memoryUsage>
        <storeUsage>
          <storeUsage limit="1 gb"/>
        </storeUsage>
        <tempUsage>
          <tempUsage limit="100 mb"/>
        </tempUsage>
      </systemUsage>
    </systemUsage>

    <transportConnectors>
      <transportConnector name="tcp" uri="tcp://localhost:61616?transport.daemon=true"/>
    </transportConnectors>
  </broker>
</beans>
Reply | Threaded
Open this post in threaded view
|

Re: Sending message to JMS endpoint is slow every x messages

iasonp
I found the solution for this problem by using a PooledConnectionFactory.
The following code solved the problem:

final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(jmsBrokerUrl);
factory.setUseAsyncSend(true);
final PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(factory);
pooledConnectionFactory.setMaxConnections(10);