Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camel # route steps vs memory/performance

Tags:

apache-camel

It might be a silly question, but say I have a hughe message that I want to process with Camel. How will the number of steps in my route affect the memory usage? Does camel deep copy my message payload for every step in the route, even if the DSL-step only reads from the message or does it do something smart here?

Is it better to keep the route down and do things in a "hughe" bean for large messages or not?

This is an example route that does various things, but not changing the payload.

from("foo:bar")
  .log(..)
  .setProperty(..)
  .setHeader(..)
  .log(..)
  .choice()
    .when(simple(... ) ) 
      .log(..)
      .to(..)
    .when(simple(..))
      .log(..)
      .to(..)
  .end()
like image 430
Petter Nordlander Avatar asked May 15 '26 07:05

Petter Nordlander


2 Answers

from my understanding, for a simple pipelined route like this, an Exchange is created containing the body once and passed along each step in the route. Other EIPs do cause the Exchange to be copied though (like multicast, wiretap, etc)...

as well, if you have steps along the route which interface with external resources which could result in any type of copy/clone/conversion/serialization of the body unnecessarily, then you might use something like the claim check pattern to reduce this.

like image 100
Ben ODay Avatar answered May 17 '26 08:05

Ben ODay


The camel exchange is the same through the route the message objects are copied or recereated in the steps. The body is just referenced though. So normally you should not have a problem.

This is handled by each camel processor individually though. So some of the processors may copy the body. Typically this is the case when the processor really works on the body. So in this case it can not be avoided.

like image 24
Christian Schneider Avatar answered May 17 '26 07:05

Christian Schneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!