You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2017/05/26 13:59:40 UTC

[HELP] - Profile camel-core for optimization and faster startup

Hi

We have found a few spots to optimize the camel-core source code for
thread contention and something else.

You can use a profile tool such as YourKit which is excellent at
identifying spots and visualizing what goes on in the JVM.

We have used it in the past to optimise stuff. However recently Luca
asked about making Camel startup faster:
https://issues.apache.org/jira/browse/CAMEL-11321

And although fast startup is not excatly the same as runtime
performance then they are still related. A profile can help identify
places for improvements.

I have pushed a sample project at
https://github.com/davsclaus/camel-profile-sample

You can then run this via

   mvn spring-boot:run

And then attach YourKit profiler.

However if you use IDEA then you can start YourKit, then from YourKit
you can choose Integrate with IDE ... and then chose IDEA and then say
ok even if IDEA is also running.

In IDEA you should see a YourKit icon if you right-click on the
SampleCamelApplication to run this application, then you can chose
that to profile, and it run the app with profiler.

You then switch to YourKit and you should start see data.
To check for thread contention, then select the "Monitor Usage" tab,
and then click the gear button with the play icon "Start Monitor
Profile" which then starts capture data.

For YourKit you can request a trial license that works for 2 weeks.


-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, May 26, 2017 at 4:42 PM, Zoran Regvart <zo...@regvart.com> wrote:
> Hi,
> awesome work Claus :)
>
> Just to add that you can do a lot with just VisualVM (bundled with
> JDK), or if you run Oracle JDK Mission Control/Java Flight Recorder
> which does not require a license when used in development[1].
>
> And let me throw a few things into the mix: there is a great tool for
> finding leaked file handles[2]; and one potential performance gain we
> can work on is using
> java.nio.file.Files.newInputStream/newOutputStream instead of
> FileInputStream/FileOutputStream as demonstrated by Hadoop[3].
>
> zoran
>
> [1] http://www.oracle.com/technetwork/java/javase/terms/license/index.html
> [2] http://file-leak-detector.kohsuke.org/
> [3] https://issues.apache.org/jira/browse/HDFS-8562
>

Thanks for the extra details.

About the file thingy, we have a ticket about it
https://issues.apache.org/jira/browse/CAMEL-11188

And btw for mission control there is a plugin in hawtio web console in
latest release so you can view it from there.

> On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> We have found a few spots to optimize the camel-core source code for
>> thread contention and something else.
>>
>> You can use a profile tool such as YourKit which is excellent at
>> identifying spots and visualizing what goes on in the JVM.
>>
>> We have used it in the past to optimise stuff. However recently Luca
>> asked about making Camel startup faster:
>> https://issues.apache.org/jira/browse/CAMEL-11321
>>
>> And although fast startup is not excatly the same as runtime
>> performance then they are still related. A profile can help identify
>> places for improvements.
>>
>> I have pushed a sample project at
>> https://github.com/davsclaus/camel-profile-sample
>>
>> You can then run this via
>>
>>    mvn spring-boot:run
>>
>> And then attach YourKit profiler.
>>
>> However if you use IDEA then you can start YourKit, then from YourKit
>> you can choose Integrate with IDE ... and then chose IDEA and then say
>> ok even if IDEA is also running.
>>
>> In IDEA you should see a YourKit icon if you right-click on the
>> SampleCamelApplication to run this application, then you can chose
>> that to profile, and it run the app with profiler.
>>
>> You then switch to YourKit and you should start see data.
>> To check for thread contention, then select the "Monitor Usage" tab,
>> and then click the gear button with the play icon "Start Monitor
>> Profile" which then starts capture data.
>>
>> For YourKit you can request a trial license that works for 2 weeks.
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Zoran Regvart



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Zoran Regvart <zo...@regvart.com>.
Hi,
awesome work Claus :)

Just to add that you can do a lot with just VisualVM (bundled with
JDK), or if you run Oracle JDK Mission Control/Java Flight Recorder
which does not require a license when used in development[1].

And let me throw a few things into the mix: there is a great tool for
finding leaked file handles[2]; and one potential performance gain we
can work on is using
java.nio.file.Files.newInputStream/newOutputStream instead of
FileInputStream/FileOutputStream as demonstrated by Hadoop[3].

zoran

[1] http://www.oracle.com/technetwork/java/javase/terms/license/index.html
[2] http://file-leak-detector.kohsuke.org/
[3] https://issues.apache.org/jira/browse/HDFS-8562

On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> We have found a few spots to optimize the camel-core source code for
> thread contention and something else.
>
> You can use a profile tool such as YourKit which is excellent at
> identifying spots and visualizing what goes on in the JVM.
>
> We have used it in the past to optimise stuff. However recently Luca
> asked about making Camel startup faster:
> https://issues.apache.org/jira/browse/CAMEL-11321
>
> And although fast startup is not excatly the same as runtime
> performance then they are still related. A profile can help identify
> places for improvements.
>
> I have pushed a sample project at
> https://github.com/davsclaus/camel-profile-sample
>
> You can then run this via
>
>    mvn spring-boot:run
>
> And then attach YourKit profiler.
>
> However if you use IDEA then you can start YourKit, then from YourKit
> you can choose Integrate with IDE ... and then chose IDEA and then say
> ok even if IDEA is also running.
>
> In IDEA you should see a YourKit icon if you right-click on the
> SampleCamelApplication to run this application, then you can chose
> that to profile, and it run the app with profiler.
>
> You then switch to YourKit and you should start see data.
> To check for thread contention, then select the "Monitor Usage" tab,
> and then click the gear button with the play icon "Start Monitor
> Profile" which then starts capture data.
>
> For YourKit you can request a trial license that works for 2 weeks.
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Zoran Regvart

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Just a heads up that I have been in contact with YourKit about
licenses for their tool for Apache Camel committers.

They got back to me and we have a project wide license that can hold
10 installed copies. I have installed one so there is 9 left.

Anyone whom is helping with this work of work is welcome to ask for a license.



On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> We have found a few spots to optimize the camel-core source code for
> thread contention and something else.
>
> You can use a profile tool such as YourKit which is excellent at
> identifying spots and visualizing what goes on in the JVM.
>
> We have used it in the past to optimise stuff. However recently Luca
> asked about making Camel startup faster:
> https://issues.apache.org/jira/browse/CAMEL-11321
>
> And although fast startup is not excatly the same as runtime
> performance then they are still related. A profile can help identify
> places for improvements.
>
> I have pushed a sample project at
> https://github.com/davsclaus/camel-profile-sample
>
> You can then run this via
>
>    mvn spring-boot:run
>
> And then attach YourKit profiler.
>
> However if you use IDEA then you can start YourKit, then from YourKit
> you can choose Integrate with IDE ... and then chose IDEA and then say
> ok even if IDEA is also running.
>
> In IDEA you should see a YourKit icon if you right-click on the
> SampleCamelApplication to run this application, then you can chose
> that to profile, and it run the app with profiler.
>
> You then switch to YourKit and you should start see data.
> To check for thread contention, then select the "Monitor Usage" tab,
> and then click the gear button with the play icon "Start Monitor
> Profile" which then starts capture data.
>
> For YourKit you can request a trial license that works for 2 weeks.
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, May 29, 2017 at 4:23 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> So today the old cruft of the legacy tracer came to bit us. There is
> something called Tracer in camel-core that was used to trace Camel
> messages. Its only in use if you do camelContext.setTracing(true) from
> Camel end users point of view. However it captures trace details
> regardless.
>
> That old cruft has been lingering for a long time, and it was really
> intended to be deprecated sooner (it slipped my radar when we marked
> stuff for @deprecated a little while back) and removed completely in
> Camel 3.0.
>
> Today we have a better way of tracing via Message History EIP and BacklogTracer.
>
> So I am working on disabling that old cruft, and remove parts of it,
> and then make camelContext.setTracing(true) use the new way via
> BacklogTracer / message history to trace instead.
>

Okay I opted to keep the old way with setTracing(true) but found a way
to optimise it so its not adding overhead if tracing is off. We can
then later migrate tracing(true) to use the new way.

>
> There is some before vs after screenshots at
> https://issues.apache.org/jira/browse/CAMEL-11360
>
> .. of a prototype that runs the camel-profile-sample project.
>
>
>
>
> On Sun, May 28, 2017 at 11:31 AM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> I have found some more spots for optimisations which I have committed
>> over the last couple of days.
>>
>> Its been several years since we last did such things last, and I have
>> to admit we have introduced some code that add more object allocation
>> and a few performance drawbacks since then.
>>
>> So with the help of profilers we should be able to improve the
>> situation for the Camel 2.20 release.
>>
>> I have to give credit to Luca for bring this idea up about making
>> Camel startup faster and look into the number of objects allocated
>> etc. Usually Camel has negligible performance overhead in the grand
>> scheme of things. But we have more fine grained performance statistics
>> today which records the time taken in every step messages are routed.
>> This uses the StopWatch object which we frankly create too many new
>> instances. So by reducing those we can reduce the object allocations
>> and therefore the JVM GC characteristics.
>>
>> In the stuff I have optimised you can find the JIRA tickets with
>> Optimise as prefix. I usually have attached some screenshots from the
>> profiler so you can see before vs after situations).
>>
>>
>> We have two areas that can be improved
>>
>> 1) startup Camel faster (jndi registry, caffine lru cache, and the
>> uuid generator is a bit slow in their constructors)
>> 2) faster routing per message at runtime (potential optimise by
>> reducing object allocations, turn off some features less/seldom in
>> use, optimise code logic in hot-spot areas, reduce size of internal
>> state objects, avoid thread contention from synchronized methods,
>> etc.)
>>
>>
>>
>> On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>> Hi
>>>
>>> We have found a few spots to optimize the camel-core source code for
>>> thread contention and something else.
>>>
>>> You can use a profile tool such as YourKit which is excellent at
>>> identifying spots and visualizing what goes on in the JVM.
>>>
>>> We have used it in the past to optimise stuff. However recently Luca
>>> asked about making Camel startup faster:
>>> https://issues.apache.org/jira/browse/CAMEL-11321
>>>
>>> And although fast startup is not excatly the same as runtime
>>> performance then they are still related. A profile can help identify
>>> places for improvements.
>>>
>>> I have pushed a sample project at
>>> https://github.com/davsclaus/camel-profile-sample
>>>
>>> You can then run this via
>>>
>>>    mvn spring-boot:run
>>>
>>> And then attach YourKit profiler.
>>>
>>> However if you use IDEA then you can start YourKit, then from YourKit
>>> you can choose Integrate with IDE ... and then chose IDEA and then say
>>> ok even if IDEA is also running.
>>>
>>> In IDEA you should see a YourKit icon if you right-click on the
>>> SampleCamelApplication to run this application, then you can chose
>>> that to profile, and it run the app with profiler.
>>>
>>> You then switch to YourKit and you should start see data.
>>> To check for thread contention, then select the "Monitor Usage" tab,
>>> and then click the gear button with the play icon "Start Monitor
>>> Profile" which then starts capture data.
>>>
>>> For YourKit you can request a trial license that works for 2 weeks.
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> http://davsclaus.com @davsclaus
>>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

So today the old cruft of the legacy tracer came to bit us. There is
something called Tracer in camel-core that was used to trace Camel
messages. Its only in use if you do camelContext.setTracing(true) from
Camel end users point of view. However it captures trace details
regardless.

That old cruft has been lingering for a long time, and it was really
intended to be deprecated sooner (it slipped my radar when we marked
stuff for @deprecated a little while back) and removed completely in
Camel 3.0.

Today we have a better way of tracing via Message History EIP and BacklogTracer.

So I am working on disabling that old cruft, and remove parts of it,
and then make camelContext.setTracing(true) use the new way via
BacklogTracer / message history to trace instead.


There is some before vs after screenshots at
https://issues.apache.org/jira/browse/CAMEL-11360

.. of a prototype that runs the camel-profile-sample project.




On Sun, May 28, 2017 at 11:31 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> I have found some more spots for optimisations which I have committed
> over the last couple of days.
>
> Its been several years since we last did such things last, and I have
> to admit we have introduced some code that add more object allocation
> and a few performance drawbacks since then.
>
> So with the help of profilers we should be able to improve the
> situation for the Camel 2.20 release.
>
> I have to give credit to Luca for bring this idea up about making
> Camel startup faster and look into the number of objects allocated
> etc. Usually Camel has negligible performance overhead in the grand
> scheme of things. But we have more fine grained performance statistics
> today which records the time taken in every step messages are routed.
> This uses the StopWatch object which we frankly create too many new
> instances. So by reducing those we can reduce the object allocations
> and therefore the JVM GC characteristics.
>
> In the stuff I have optimised you can find the JIRA tickets with
> Optimise as prefix. I usually have attached some screenshots from the
> profiler so you can see before vs after situations).
>
>
> We have two areas that can be improved
>
> 1) startup Camel faster (jndi registry, caffine lru cache, and the
> uuid generator is a bit slow in their constructors)
> 2) faster routing per message at runtime (potential optimise by
> reducing object allocations, turn off some features less/seldom in
> use, optimise code logic in hot-spot areas, reduce size of internal
> state objects, avoid thread contention from synchronized methods,
> etc.)
>
>
>
> On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> We have found a few spots to optimize the camel-core source code for
>> thread contention and something else.
>>
>> You can use a profile tool such as YourKit which is excellent at
>> identifying spots and visualizing what goes on in the JVM.
>>
>> We have used it in the past to optimise stuff. However recently Luca
>> asked about making Camel startup faster:
>> https://issues.apache.org/jira/browse/CAMEL-11321
>>
>> And although fast startup is not excatly the same as runtime
>> performance then they are still related. A profile can help identify
>> places for improvements.
>>
>> I have pushed a sample project at
>> https://github.com/davsclaus/camel-profile-sample
>>
>> You can then run this via
>>
>>    mvn spring-boot:run
>>
>> And then attach YourKit profiler.
>>
>> However if you use IDEA then you can start YourKit, then from YourKit
>> you can choose Integrate with IDE ... and then chose IDEA and then say
>> ok even if IDEA is also running.
>>
>> In IDEA you should see a YourKit icon if you right-click on the
>> SampleCamelApplication to run this application, then you can chose
>> that to profile, and it run the app with profiler.
>>
>> You then switch to YourKit and you should start see data.
>> To check for thread contention, then select the "Monitor Usage" tab,
>> and then click the gear button with the play icon "Start Monitor
>> Profile" which then starts capture data.
>>
>> For YourKit you can request a trial license that works for 2 weeks.
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, May 29, 2017 at 7:30 AM, Luca Burgazzoli <lb...@gmail.com> wrote:
> It may be worth adding a small number of JMH micro benchmarks - not to
> be used as performances metrics - on camel core so we can spot
> potential regressions.
>

A candidate for JMH micro benchmark would be the
org.apache.camel.impl.ActiveMQUuidGenerator#generateUuid which is used
a lot for generating all the uuids in Camel.

We may look at trying to optimise that method.

Contributions is welcome. Maybe the JMH tests need to be separated
from camel-core and placed in eg,
tests/jmh-tests or something.



> ---
> Luca Burgazzoli
>
>
> On Sun, May 28, 2017 at 11:31 AM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> I have found some more spots for optimisations which I have committed
>> over the last couple of days.
>>
>> Its been several years since we last did such things last, and I have
>> to admit we have introduced some code that add more object allocation
>> and a few performance drawbacks since then.
>>
>> So with the help of profilers we should be able to improve the
>> situation for the Camel 2.20 release.
>>
>> I have to give credit to Luca for bring this idea up about making
>> Camel startup faster and look into the number of objects allocated
>> etc. Usually Camel has negligible performance overhead in the grand
>> scheme of things. But we have more fine grained performance statistics
>> today which records the time taken in every step messages are routed.
>> This uses the StopWatch object which we frankly create too many new
>> instances. So by reducing those we can reduce the object allocations
>> and therefore the JVM GC characteristics.
>>
>> In the stuff I have optimised you can find the JIRA tickets with
>> Optimise as prefix. I usually have attached some screenshots from the
>> profiler so you can see before vs after situations).
>>
>>
>> We have two areas that can be improved
>>
>> 1) startup Camel faster (jndi registry, caffine lru cache, and the
>> uuid generator is a bit slow in their constructors)
>> 2) faster routing per message at runtime (potential optimise by
>> reducing object allocations, turn off some features less/seldom in
>> use, optimise code logic in hot-spot areas, reduce size of internal
>> state objects, avoid thread contention from synchronized methods,
>> etc.)
>>
>>
>>
>> On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>> Hi
>>>
>>> We have found a few spots to optimize the camel-core source code for
>>> thread contention and something else.
>>>
>>> You can use a profile tool such as YourKit which is excellent at
>>> identifying spots and visualizing what goes on in the JVM.
>>>
>>> We have used it in the past to optimise stuff. However recently Luca
>>> asked about making Camel startup faster:
>>> https://issues.apache.org/jira/browse/CAMEL-11321
>>>
>>> And although fast startup is not excatly the same as runtime
>>> performance then they are still related. A profile can help identify
>>> places for improvements.
>>>
>>> I have pushed a sample project at
>>> https://github.com/davsclaus/camel-profile-sample
>>>
>>> You can then run this via
>>>
>>>    mvn spring-boot:run
>>>
>>> And then attach YourKit profiler.
>>>
>>> However if you use IDEA then you can start YourKit, then from YourKit
>>> you can choose Integrate with IDE ... and then chose IDEA and then say
>>> ok even if IDEA is also running.
>>>
>>> In IDEA you should see a YourKit icon if you right-click on the
>>> SampleCamelApplication to run this application, then you can chose
>>> that to profile, and it run the app with profiler.
>>>
>>> You then switch to YourKit and you should start see data.
>>> To check for thread contention, then select the "Monitor Usage" tab,
>>> and then click the gear button with the play icon "Start Monitor
>>> Profile" which then starts capture data.
>>>
>>> For YourKit you can request a trial license that works for 2 weeks.
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> http://davsclaus.com @davsclaus
>>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, May 29, 2017 at 7:30 AM, Luca Burgazzoli <lb...@gmail.com> wrote:
> It may be worth adding a small number of JMH micro benchmarks - not to
> be used as performances metrics - on camel core so we can spot
> potential regressions.
>

Yeah we can try that.

> ---
> Luca Burgazzoli
>
>
> On Sun, May 28, 2017 at 11:31 AM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> I have found some more spots for optimisations which I have committed
>> over the last couple of days.
>>
>> Its been several years since we last did such things last, and I have
>> to admit we have introduced some code that add more object allocation
>> and a few performance drawbacks since then.
>>
>> So with the help of profilers we should be able to improve the
>> situation for the Camel 2.20 release.
>>
>> I have to give credit to Luca for bring this idea up about making
>> Camel startup faster and look into the number of objects allocated
>> etc. Usually Camel has negligible performance overhead in the grand
>> scheme of things. But we have more fine grained performance statistics
>> today which records the time taken in every step messages are routed.
>> This uses the StopWatch object which we frankly create too many new
>> instances. So by reducing those we can reduce the object allocations
>> and therefore the JVM GC characteristics.
>>
>> In the stuff I have optimised you can find the JIRA tickets with
>> Optimise as prefix. I usually have attached some screenshots from the
>> profiler so you can see before vs after situations).
>>
>>
>> We have two areas that can be improved
>>
>> 1) startup Camel faster (jndi registry, caffine lru cache, and the
>> uuid generator is a bit slow in their constructors)
>> 2) faster routing per message at runtime (potential optimise by
>> reducing object allocations, turn off some features less/seldom in
>> use, optimise code logic in hot-spot areas, reduce size of internal
>> state objects, avoid thread contention from synchronized methods,
>> etc.)
>>
>>
>>
>> On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>> Hi
>>>
>>> We have found a few spots to optimize the camel-core source code for
>>> thread contention and something else.
>>>
>>> You can use a profile tool such as YourKit which is excellent at
>>> identifying spots and visualizing what goes on in the JVM.
>>>
>>> We have used it in the past to optimise stuff. However recently Luca
>>> asked about making Camel startup faster:
>>> https://issues.apache.org/jira/browse/CAMEL-11321
>>>
>>> And although fast startup is not excatly the same as runtime
>>> performance then they are still related. A profile can help identify
>>> places for improvements.
>>>
>>> I have pushed a sample project at
>>> https://github.com/davsclaus/camel-profile-sample
>>>
>>> You can then run this via
>>>
>>>    mvn spring-boot:run
>>>
>>> And then attach YourKit profiler.
>>>
>>> However if you use IDEA then you can start YourKit, then from YourKit
>>> you can choose Integrate with IDE ... and then chose IDEA and then say
>>> ok even if IDEA is also running.
>>>
>>> In IDEA you should see a YourKit icon if you right-click on the
>>> SampleCamelApplication to run this application, then you can chose
>>> that to profile, and it run the app with profiler.
>>>
>>> You then switch to YourKit and you should start see data.
>>> To check for thread contention, then select the "Monitor Usage" tab,
>>> and then click the gear button with the play icon "Start Monitor
>>> Profile" which then starts capture data.
>>>
>>> For YourKit you can request a trial license that works for 2 weeks.
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> http://davsclaus.com @davsclaus
>>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, May 29, 2017 at 7:30 AM, Luca Burgazzoli <lb...@gmail.com> wrote:
> It may be worth adding a small number of JMH micro benchmarks - not to
> be used as performances metrics - on camel core so we can spot
> potential regressions.
>

I just added our first JMH tests, which you can find in the
tests/camel-jmh directory.



> ---
> Luca Burgazzoli
>
>
> On Sun, May 28, 2017 at 11:31 AM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> I have found some more spots for optimisations which I have committed
>> over the last couple of days.
>>
>> Its been several years since we last did such things last, and I have
>> to admit we have introduced some code that add more object allocation
>> and a few performance drawbacks since then.
>>
>> So with the help of profilers we should be able to improve the
>> situation for the Camel 2.20 release.
>>
>> I have to give credit to Luca for bring this idea up about making
>> Camel startup faster and look into the number of objects allocated
>> etc. Usually Camel has negligible performance overhead in the grand
>> scheme of things. But we have more fine grained performance statistics
>> today which records the time taken in every step messages are routed.
>> This uses the StopWatch object which we frankly create too many new
>> instances. So by reducing those we can reduce the object allocations
>> and therefore the JVM GC characteristics.
>>
>> In the stuff I have optimised you can find the JIRA tickets with
>> Optimise as prefix. I usually have attached some screenshots from the
>> profiler so you can see before vs after situations).
>>
>>
>> We have two areas that can be improved
>>
>> 1) startup Camel faster (jndi registry, caffine lru cache, and the
>> uuid generator is a bit slow in their constructors)
>> 2) faster routing per message at runtime (potential optimise by
>> reducing object allocations, turn off some features less/seldom in
>> use, optimise code logic in hot-spot areas, reduce size of internal
>> state objects, avoid thread contention from synchronized methods,
>> etc.)
>>
>>
>>
>> On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>> Hi
>>>
>>> We have found a few spots to optimize the camel-core source code for
>>> thread contention and something else.
>>>
>>> You can use a profile tool such as YourKit which is excellent at
>>> identifying spots and visualizing what goes on in the JVM.
>>>
>>> We have used it in the past to optimise stuff. However recently Luca
>>> asked about making Camel startup faster:
>>> https://issues.apache.org/jira/browse/CAMEL-11321
>>>
>>> And although fast startup is not excatly the same as runtime
>>> performance then they are still related. A profile can help identify
>>> places for improvements.
>>>
>>> I have pushed a sample project at
>>> https://github.com/davsclaus/camel-profile-sample
>>>
>>> You can then run this via
>>>
>>>    mvn spring-boot:run
>>>
>>> And then attach YourKit profiler.
>>>
>>> However if you use IDEA then you can start YourKit, then from YourKit
>>> you can choose Integrate with IDE ... and then chose IDEA and then say
>>> ok even if IDEA is also running.
>>>
>>> In IDEA you should see a YourKit icon if you right-click on the
>>> SampleCamelApplication to run this application, then you can chose
>>> that to profile, and it run the app with profiler.
>>>
>>> You then switch to YourKit and you should start see data.
>>> To check for thread contention, then select the "Monitor Usage" tab,
>>> and then click the gear button with the play icon "Start Monitor
>>> Profile" which then starts capture data.
>>>
>>> For YourKit you can request a trial license that works for 2 weeks.
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> http://davsclaus.com @davsclaus
>>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Luca Burgazzoli <lb...@gmail.com>.
It may be worth adding a small number of JMH micro benchmarks - not to
be used as performances metrics - on camel core so we can spot
potential regressions.

---
Luca Burgazzoli


On Sun, May 28, 2017 at 11:31 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> I have found some more spots for optimisations which I have committed
> over the last couple of days.
>
> Its been several years since we last did such things last, and I have
> to admit we have introduced some code that add more object allocation
> and a few performance drawbacks since then.
>
> So with the help of profilers we should be able to improve the
> situation for the Camel 2.20 release.
>
> I have to give credit to Luca for bring this idea up about making
> Camel startup faster and look into the number of objects allocated
> etc. Usually Camel has negligible performance overhead in the grand
> scheme of things. But we have more fine grained performance statistics
> today which records the time taken in every step messages are routed.
> This uses the StopWatch object which we frankly create too many new
> instances. So by reducing those we can reduce the object allocations
> and therefore the JVM GC characteristics.
>
> In the stuff I have optimised you can find the JIRA tickets with
> Optimise as prefix. I usually have attached some screenshots from the
> profiler so you can see before vs after situations).
>
>
> We have two areas that can be improved
>
> 1) startup Camel faster (jndi registry, caffine lru cache, and the
> uuid generator is a bit slow in their constructors)
> 2) faster routing per message at runtime (potential optimise by
> reducing object allocations, turn off some features less/seldom in
> use, optimise code logic in hot-spot areas, reduce size of internal
> state objects, avoid thread contention from synchronized methods,
> etc.)
>
>
>
> On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> We have found a few spots to optimize the camel-core source code for
>> thread contention and something else.
>>
>> You can use a profile tool such as YourKit which is excellent at
>> identifying spots and visualizing what goes on in the JVM.
>>
>> We have used it in the past to optimise stuff. However recently Luca
>> asked about making Camel startup faster:
>> https://issues.apache.org/jira/browse/CAMEL-11321
>>
>> And although fast startup is not excatly the same as runtime
>> performance then they are still related. A profile can help identify
>> places for improvements.
>>
>> I have pushed a sample project at
>> https://github.com/davsclaus/camel-profile-sample
>>
>> You can then run this via
>>
>>    mvn spring-boot:run
>>
>> And then attach YourKit profiler.
>>
>> However if you use IDEA then you can start YourKit, then from YourKit
>> you can choose Integrate with IDE ... and then chose IDEA and then say
>> ok even if IDEA is also running.
>>
>> In IDEA you should see a YourKit icon if you right-click on the
>> SampleCamelApplication to run this application, then you can chose
>> that to profile, and it run the app with profiler.
>>
>> You then switch to YourKit and you should start see data.
>> To check for thread contention, then select the "Monitor Usage" tab,
>> and then click the gear button with the play icon "Start Monitor
>> Profile" which then starts capture data.
>>
>> For YourKit you can request a trial license that works for 2 weeks.
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I have found some more spots for optimisations which I have committed
over the last couple of days.

Its been several years since we last did such things last, and I have
to admit we have introduced some code that add more object allocation
and a few performance drawbacks since then.

So with the help of profilers we should be able to improve the
situation for the Camel 2.20 release.

I have to give credit to Luca for bring this idea up about making
Camel startup faster and look into the number of objects allocated
etc. Usually Camel has negligible performance overhead in the grand
scheme of things. But we have more fine grained performance statistics
today which records the time taken in every step messages are routed.
This uses the StopWatch object which we frankly create too many new
instances. So by reducing those we can reduce the object allocations
and therefore the JVM GC characteristics.

In the stuff I have optimised you can find the JIRA tickets with
Optimise as prefix. I usually have attached some screenshots from the
profiler so you can see before vs after situations).


We have two areas that can be improved

1) startup Camel faster (jndi registry, caffine lru cache, and the
uuid generator is a bit slow in their constructors)
2) faster routing per message at runtime (potential optimise by
reducing object allocations, turn off some features less/seldom in
use, optimise code logic in hot-spot areas, reduce size of internal
state objects, avoid thread contention from synchronized methods,
etc.)



On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> We have found a few spots to optimize the camel-core source code for
> thread contention and something else.
>
> You can use a profile tool such as YourKit which is excellent at
> identifying spots and visualizing what goes on in the JVM.
>
> We have used it in the past to optimise stuff. However recently Luca
> asked about making Camel startup faster:
> https://issues.apache.org/jira/browse/CAMEL-11321
>
> And although fast startup is not excatly the same as runtime
> performance then they are still related. A profile can help identify
> places for improvements.
>
> I have pushed a sample project at
> https://github.com/davsclaus/camel-profile-sample
>
> You can then run this via
>
>    mvn spring-boot:run
>
> And then attach YourKit profiler.
>
> However if you use IDEA then you can start YourKit, then from YourKit
> you can choose Integrate with IDE ... and then chose IDEA and then say
> ok even if IDEA is also running.
>
> In IDEA you should see a YourKit icon if you right-click on the
> SampleCamelApplication to run this application, then you can chose
> that to profile, and it run the app with profiler.
>
> You then switch to YourKit and you should start see data.
> To check for thread contention, then select the "Monitor Usage" tab,
> and then click the gear button with the play icon "Start Monitor
> Profile" which then starts capture data.
>
> For YourKit you can request a trial license that works for 2 weeks.
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I just pushed some commits that improves a little bit the startup of
Apache Camel. The Caffeine LRUCache will upon initialization block for
150 - 200 millis, which we can do in parallel while Camel is being
started. Before this initialization was always forced when you created
a new instance of DefaultCamelContext which means it was blocking for
any runtime you were using. We now do a special warm-up of the
LRUCache in a separate thread to allow the constructor of
DefaultCamelContext to carry on and continue starting up. This makes
starting Camel on Spring Boot etc faster as there is plenty of Spring
Boot startup happening at the same time.


On Fri, Jun 30, 2017 at 11:56 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> I found some other rooms for optimisations such as
> - invoking the base of the core type converters faster
> - jmx mbean of processors in the routes is using advice over wrapped
> processor to reduce garbage collection
> - simple language now caches evaluated expressions/predicates which
> yields faster evaluation when nested functions are used
> - reduced the number of objects allocated at runtime to reduce garbage
> collection
>
>
>
>
> On Fri, Jun 23, 2017 at 8:42 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> Just a little status update, that after a bunch of different
>> optimisations, then the YourKit profiler is now down to showing that
>> the type converter registry and the uuid generator is potential
>> hot-spots, where the former is used a lot and we can optimise the
>> conversions for the core converters which I have logged a ticket
>> about. And the latter generates an string uuid for each exchange which
>> is a little bit long. As its sequencer based and have a fixed prefix,
>> then maybe there is some clever optimisation (essentially only the
>> sequence is different as they share the same prefix/seed). But its
>> already optimise as much by adding two strings together via
>> StringBuilder.
>>
>>
>>
>> On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>> Hi
>>>
>>> We have found a few spots to optimize the camel-core source code for
>>> thread contention and something else.
>>>
>>> You can use a profile tool such as YourKit which is excellent at
>>> identifying spots and visualizing what goes on in the JVM.
>>>
>>> We have used it in the past to optimise stuff. However recently Luca
>>> asked about making Camel startup faster:
>>> https://issues.apache.org/jira/browse/CAMEL-11321
>>>
>>> And although fast startup is not excatly the same as runtime
>>> performance then they are still related. A profile can help identify
>>> places for improvements.
>>>
>>> I have pushed a sample project at
>>> https://github.com/davsclaus/camel-profile-sample
>>>
>>> You can then run this via
>>>
>>>    mvn spring-boot:run
>>>
>>> And then attach YourKit profiler.
>>>
>>> However if you use IDEA then you can start YourKit, then from YourKit
>>> you can choose Integrate with IDE ... and then chose IDEA and then say
>>> ok even if IDEA is also running.
>>>
>>> In IDEA you should see a YourKit icon if you right-click on the
>>> SampleCamelApplication to run this application, then you can chose
>>> that to profile, and it run the app with profiler.
>>>
>>> You then switch to YourKit and you should start see data.
>>> To check for thread contention, then select the "Monitor Usage" tab,
>>> and then click the gear button with the play icon "Start Monitor
>>> Profile" which then starts capture data.
>>>
>>> For YourKit you can request a trial license that works for 2 weeks.
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> http://davsclaus.com @davsclaus
>>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I found some other rooms for optimisations such as
- invoking the base of the core type converters faster
- jmx mbean of processors in the routes is using advice over wrapped
processor to reduce garbage collection
- simple language now caches evaluated expressions/predicates which
yields faster evaluation when nested functions are used
- reduced the number of objects allocated at runtime to reduce garbage
collection




On Fri, Jun 23, 2017 at 8:42 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Just a little status update, that after a bunch of different
> optimisations, then the YourKit profiler is now down to showing that
> the type converter registry and the uuid generator is potential
> hot-spots, where the former is used a lot and we can optimise the
> conversions for the core converters which I have logged a ticket
> about. And the latter generates an string uuid for each exchange which
> is a little bit long. As its sequencer based and have a fixed prefix,
> then maybe there is some clever optimisation (essentially only the
> sequence is different as they share the same prefix/seed). But its
> already optimise as much by adding two strings together via
> StringBuilder.
>
>
>
> On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> We have found a few spots to optimize the camel-core source code for
>> thread contention and something else.
>>
>> You can use a profile tool such as YourKit which is excellent at
>> identifying spots and visualizing what goes on in the JVM.
>>
>> We have used it in the past to optimise stuff. However recently Luca
>> asked about making Camel startup faster:
>> https://issues.apache.org/jira/browse/CAMEL-11321
>>
>> And although fast startup is not excatly the same as runtime
>> performance then they are still related. A profile can help identify
>> places for improvements.
>>
>> I have pushed a sample project at
>> https://github.com/davsclaus/camel-profile-sample
>>
>> You can then run this via
>>
>>    mvn spring-boot:run
>>
>> And then attach YourKit profiler.
>>
>> However if you use IDEA then you can start YourKit, then from YourKit
>> you can choose Integrate with IDE ... and then chose IDEA and then say
>> ok even if IDEA is also running.
>>
>> In IDEA you should see a YourKit icon if you right-click on the
>> SampleCamelApplication to run this application, then you can chose
>> that to profile, and it run the app with profiler.
>>
>> You then switch to YourKit and you should start see data.
>> To check for thread contention, then select the "Monitor Usage" tab,
>> and then click the gear button with the play icon "Start Monitor
>> Profile" which then starts capture data.
>>
>> For YourKit you can request a trial license that works for 2 weeks.
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: [HELP] - Profile camel-core for optimization and faster startup

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Just a little status update, that after a bunch of different
optimisations, then the YourKit profiler is now down to showing that
the type converter registry and the uuid generator is potential
hot-spots, where the former is used a lot and we can optimise the
conversions for the core converters which I have logged a ticket
about. And the latter generates an string uuid for each exchange which
is a little bit long. As its sequencer based and have a fixed prefix,
then maybe there is some clever optimisation (essentially only the
sequence is different as they share the same prefix/seed). But its
already optimise as much by adding two strings together via
StringBuilder.



On Fri, May 26, 2017 at 3:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> We have found a few spots to optimize the camel-core source code for
> thread contention and something else.
>
> You can use a profile tool such as YourKit which is excellent at
> identifying spots and visualizing what goes on in the JVM.
>
> We have used it in the past to optimise stuff. However recently Luca
> asked about making Camel startup faster:
> https://issues.apache.org/jira/browse/CAMEL-11321
>
> And although fast startup is not excatly the same as runtime
> performance then they are still related. A profile can help identify
> places for improvements.
>
> I have pushed a sample project at
> https://github.com/davsclaus/camel-profile-sample
>
> You can then run this via
>
>    mvn spring-boot:run
>
> And then attach YourKit profiler.
>
> However if you use IDEA then you can start YourKit, then from YourKit
> you can choose Integrate with IDE ... and then chose IDEA and then say
> ok even if IDEA is also running.
>
> In IDEA you should see a YourKit icon if you right-click on the
> SampleCamelApplication to run this application, then you can chose
> that to profile, and it run the app with profiler.
>
> You then switch to YourKit and you should start see data.
> To check for thread contention, then select the "Monitor Usage" tab,
> and then click the gear button with the play icon "Start Monitor
> Profile" which then starts capture data.
>
> For YourKit you can request a trial license that works for 2 weeks.
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2