Hi,
I implemented this but I'm facing severe performance problem. My legacy
application handles this by separated threads and the performance is
more than 10 times of my Camel application. I don't know if it's my
Camel application problem or it's the problem of Camel. Here the detail
of my application:
My Route:
from(NEW_QUEUE).threads(threadNum).unmarshal().json(JsonLibrary.Gson,
IndexDoc.class)
.process(processor1)
.process(processor2)
.process(processor3)
.process(processor4)
.process(processor5)
.process(processor6).wireTap(MY_COMP_URL)
.marshal().json(JsonLibrary.Gson).to(INDEX_QUEUE);
My CamelContext Settings:
int threadNum=20;
int maxThreadNum=50;
CamelContext context = new DefaultCamelContext();
ThreadPoolProfile
threadPool=context.getExecutorServiceManager().getDefaultThreadPoolProfile();
threadPool.setPoolSize(threadNum);
threadPool.setMaxPoolSize(maxThreadNum);
context.setStreamCaching(true);
//context.addComponent("jms",JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
String mqServer=ConfigSupport.getConfig("mq_server");
ActiveMQConfiguration config = new ActiveMQConfiguration();
config.setBrokerURL(mqServer);
config.setUsePooledConnection(true);
ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory(mqServer);
// optimize AMQ to be as fast as possible so unit testing is quicker
connectionFactory.setCopyMessageOnSend(false);
connectionFactory.setOptimizeAcknowledge(true);
connectionFactory.setOptimizedMessageDispatch(true);
// use a pooled connection factory
PooledConnectionFactory pooled = new
PooledConnectionFactory(connectionFactory);
pooled.setMaxConnections(maxThreadNum);
config.setConnectionFactory(pooled);
context.addComponent("activemq", new ActiveMQComponent(config));
Is there any problem in above code? My legacy application uses 10
threads and the route logic is exactly same. I even increased the
threadNum of my Camel application to 50 and max to 100 but there is no
obvious improvement.
δΊ 2014/2/21 17:18, Henryk Konsek ει:
You can use ThreadLocal to cache the instance of your library per
thread in the processor.
private ThreadLocal<NonThreadSafeExpensiveToCreateUtil> util =
new ThreadLocal<NonThreadSafeExpensiveToCreateUtil>() {
@Override public NonThreadSafeExpensiveToCreateUtil initialValue() {
return new NonThreadSafeExpensiveToCreateUtil();
}
};
As Camel uses pool of threads, it will keep a single instance of the
util bound to each thread executing the processor.
Cheers.