camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > Camel 2.x Speed optimizations
Date Tue, 14 Jul 2009 10:44:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">Camel
2.x Speed optimizations</a></h2>
     <h4>Page <b>edited</b> by             <a href="">Claus
     <div class="notificationGreySide">
         <h2><a name="Camel2.xSpeedoptimizations-Camel2.xSpeedoptimizations"></a>Camel
2.x Speed optimizations</h2>

<p>This design page is about how to optimize and make Camel 2.x more performant. </p>

<h3><a name="Camel2.xSpeedoptimizations-ReduceExchangecopying"></a>Reduce
Exchange copying</h3>
<p>The first issue to address is to reduce the need for copying exchanges.</p>

<p>Currently Camel does defensive copying of the current Exchange being routed. This
happens in <tt>org.apache.camel.processor.Pipeline</tt>.<br/>
This hotspot should be reduced as the Pipeline should <b>not</b> do defensive
copy of the Exchange.</p>

<h4><a name="Camel2.xSpeedoptimizations-Onlywhenredelivering"></a>Only when
<p>A defensive copy of the Exchange is <b>only</b> needed when Camel does
redelivery using its <a href="/confluence/display/CAMEL/Error+Handler" title="Error Handler">Error
Handler</a> features. So the goal is to move<br/>
the defensive copy from the Pipeline to <tt>org.apache.camel.processor.RedeliveryErrorHandler</tt>.
As this error handler is the base for doing redelivery within Camel itself. Then the speed
gain is when users do not use this error handler at all.</p>

<h4><a name="Camel2.xSpeedoptimizations-OptimizeRedeliveryErrorHandler"></a>Optimize
<p>A second goal is to implement logic in RedeliveryErrorHandler to only do defensive
copying if a redelivery is possible. End users need to explicit enable redelivery in Camel.
By implementing logic if a redelivery is ever possible or not we can reduce the copying even

<h4><a name="Camel2.xSpeedoptimizations-OnlycopyMessageandnotExchange"></a>Only
copy Message and not Exchange</h4>
<p>Another goal is to only copy the IN message as its the <b>input</b> to
a processor, and where the processor can mutate it. So instead of copying the entire Exchange
we can reduce it to only copying the IN message. This enforces the convention that Exchange
properties will not be copied.</p>

<h4><a name="Camel2.xSpeedoptimizations-NotmanyprocessorscanmutateINmessage"></a>Not
many processors can mutate IN message</h4>
<p>Many of the processors (eg transports, protocols etc.) do not mutate/modify the IN
message so we can leverage this fact that a copy is only needed in some situations. For instance
the File producer do not mutate the IN message so we do not need to copy it even if we do

<p>Logic can be build in to cater for this. For instance:</p>
<ul class="alternate" type="square">
	<li>Some interface to indicate whether a Processor can mutate or not.</li>
	<li>.process can mutate (you get access to the entire Exchange)</li>
	<li>.bean can mutate (only in some situations)</li>
	<li>we can allow end users to indicate whether they mutate the exchange or not</li>
	<li>we can let end users set a flag on the exchange if it was mutated</li>
	<li>we can add some proxy if getBody/setBody getHeader/setHeader was invoked on IN
message to indicate if it was possible to mutate it</li>

<p>We dont have to go all the way, by having just all the Camel component/processors
being able to indicate whether they can mutate or not is a big win.<br/>
The optimizations of bean/process can be secondary objective as it can be a bit overkill and

<h4><a name="Camel2.xSpeedoptimizations-UsingYourKitprofiler"></a>Using
YourKit profiler</h4>
<p>We should use a profiler to aid find hotspots to optimize. </p>

<p>Claus used YourKit to find the following hot spots:</p>
<ul class="alternate" type="square">
	<li>type converter to String could be greatly optimized as it tended to go over fallback
	<li>recipient list with only 1 element could be avoid to not use a Scanner as creating
a Scanner costs performance</li>

<h4><a name="Camel2.xSpeedoptimizations-Performancetests"></a>Performance
<p>We should have some performance tests we can run and see what we archive.</p>

<p>A very crude experiment from Claus showed 2x gain by avoiding doing excessive exchange
copies in the <tt>RoutePerformanceTest</tt> unit test by modifying the <tt>Pipeline</tt>
processor to not do a copy of the Exchange.</p>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>

       <a href="">View
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message