You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sarveswaran_m <sa...@yahoo.com> on 2014/07/30 12:27:18 UTC

one context or multiple contexts?

We have a bunch of independent routes.
We run camel in stand-alone mode.
Ideally, we can run all our routes in a single camel context.
In such a scenario, a single greedy route consuming excess memory can bring
down the entire JVM.
There by, bringing all the routes down.
Is there any way this can be prevented in camel?

The alternate is to run each route in a separate context (in a separate JVM,
as a separate process)
Is it a good idea to run each route as a separate process?
How does it compare with running multiple routes from a single context?
What is the trade-off?

Note:
We have tom-cat web container in our deployment environment.
Considering the 'greedy-route' scenario explained above, we are not bundling
camel with tom-cat.
Is there any provision in tomcat that addresses the 'greedy-route' scenario?




--
View this message in context: http://camel.465427.n5.nabble.com/one-context-or-multiple-contexts-tp5754635.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: one context or multiple contexts?

Posted by Matt Sicker <bo...@gmail.com>.
It's certainly far easier to use in such a scenario. Multiple CamelContexts
prevents you from using the direct: and seda: components (to name two) in
between contexts. Some components may also not be using very modular
libraries behind the scenes which may be using singletons and such. In such
a scenario, I find that using OSGi (like through
Karaf/ServiceMix/Fabric8/etc.) helps a lot in that regard.


On 13 August 2014 11:30, peter_minearo@skycreek.com <
peter_minearo@skycreek.com> wrote:

> In doing research about implementing multiple CamelContexts within a single
> JVM, I have seen the information on this page pop up in several different
> places.
>
> http://camel.apache.org/why-use-multiple-camelcontext.html
>
> "In general, you don't tend to want multiple camel contexts in your
> application, if you're running Camel as a standalone Java instance."
>
> Is there a technical reason why an application would only want 1
> CamelContext per JVM?  Meaning, does the CamelContext create a singleton
> classes that have a certain state which may be changed by a different
> CamelContext?
>
> If there isn't, could we get the documentation updated to be a little more
> accurate?
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/one-context-or-multiple-contexts-tp5754635p5755184.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Matt Sicker <bo...@gmail.com>

Re: one context or multiple contexts?

Posted by "peter_minearo@skycreek.com" <pe...@skycreek.com>.
In doing research about implementing multiple CamelContexts within a single
JVM, I have seen the information on this page pop up in several different
places.

http://camel.apache.org/why-use-multiple-camelcontext.html

"In general, you don't tend to want multiple camel contexts in your
application, if you're running Camel as a standalone Java instance."

Is there a technical reason why an application would only want 1
CamelContext per JVM?  Meaning, does the CamelContext create a singleton
classes that have a certain state which may be changed by a different
CamelContext?

If there isn't, could we get the documentation updated to be a little more
accurate?

 



--
View this message in context: http://camel.465427.n5.nabble.com/one-context-or-multiple-contexts-tp5754635p5755184.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: one context or multiple contexts?

Posted by Bilgin Ibryam <bi...@gmail.com>.
Well done. I think you found the golden middle ground!


On 31 July 2014 11:36, sarveswaran_m <sa...@yahoo.com> wrote:

> Based on th replies and search done so far, we have come to the following
> conclusion:
>
> Spawning separate JVM for each route is greedy.
> Bundling all routes with-in a single JVM makes the solution vulnerable to
> greedy-route problem.
> Bundling related routes together and deploying them with in one JVM seems
> to
> the reasonable middle-ground.
>
> We are considering Master-slave fail over for routes as well.
> Thanks for the useful replies.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/one-context-or-multiple-contexts-tp5754635p5754722.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Bilgin Ibryam

Red Hat, Inc.
Apache Camel & Apache OFBiz committer
Blog: ofbizian.com
Twitter: @bibryam <https://twitter.com/bibryam>

Author of Instant Apache Camel Message Routing
http://www.amazon.com/dp/1783283475

Re: one context or multiple contexts?

Posted by sarveswaran_m <sa...@yahoo.com>.
Based on th replies and search done so far, we have come to the following
conclusion:

Spawning separate JVM for each route is greedy.
Bundling all routes with-in a single JVM makes the solution vulnerable to
greedy-route problem.
Bundling related routes together and deploying them with in one JVM seems to
the reasonable middle-ground. 

We are considering Master-slave fail over for routes as well.
Thanks for the useful replies.



--
View this message in context: http://camel.465427.n5.nabble.com/one-context-or-multiple-contexts-tp5754635p5754722.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: one context or multiple contexts?

Posted by "Elvio Caruana (ecaruana)" <ec...@cisco.com>.
This is very subjective, but to me "greedy route" sets alarm bells ringing. Can't you put some checks in place? Throttling, delayer, load-balancer EIPs? Having it in a separate process mitigates the problem but is definitely not a solution. You've just shifted the problem.

Elvio

-----Original Message-----
From: sarveswaran_m [mailto:sarveswaran_m@yahoo.com] 
Sent: 30 July 2014 11:27
To: users@camel.apache.org
Subject: one context or multiple contexts?

We have a bunch of independent routes.
We run camel in stand-alone mode.
Ideally, we can run all our routes in a single camel context.
In such a scenario, a single greedy route consuming excess memory can bring down the entire JVM.
There by, bringing all the routes down.
Is there any way this can be prevented in camel?

The alternate is to run each route in a separate context (in a separate JVM, as a separate process) Is it a good idea to run each route as a separate process?
How does it compare with running multiple routes from a single context?
What is the trade-off?

Note:
We have tom-cat web container in our deployment environment.
Considering the 'greedy-route' scenario explained above, we are not bundling camel with tom-cat.
Is there any provision in tomcat that addresses the 'greedy-route' scenario?




--
View this message in context: http://camel.465427.n5.nabble.com/one-context-or-multiple-contexts-tp5754635.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: one context or multiple contexts?

Posted by Matt Sicker <bo...@gmail.com>.
The way we do this at my work (using OSGi) is that each bundle gets its own
CamelContext. We're using Blueprint, but even if we were to use Declarative
Services or similar, I'd still implement it as a ServiceFactory (or the
managed version if I wanted to include configurable parameters) so that
each bundle got its own CamelContext. This is particularly useful for hot
deployments of pieces so that you don't have to bring everything down for a
hotfix or upgrade.


On 30 July 2014 17:37, Bilgin Ibryam <bi...@gmail.com> wrote:

> Inline
>
> On 30 July 2014 11:27, sarveswaran_m <sa...@yahoo.com> wrote:
>
> > We have a bunch of independent routes.
> > We run camel in stand-alone mode.
> > Ideally, we can run all our routes in a single camel context.
> > In such a scenario, a single greedy route consuming excess memory can
> bring
> > down the entire JVM.
> > There by, bringing all the routes down.
> > Is there any way this can be prevented in camel?
> >
>
> If there is a chance that a route brings the whole jvm down and you cannot
> afford any down time, your best option is to have another jvm to take over.
> Here are few ways to achieve master/slave configuration for camel routes
> [1]
>
>
> >
> > The alternate is to run each route in a separate context (in a separate
> > JVM,
> > as a separate process)
> > Is it a good idea to run each route as a separate process?
> >
> How does it compare with running multiple routes from a single context?
> > What is the trade-off?
> >
>
> First, having one camel context or multipe camel contexts is not very
> different as long as they are in the same JVM. Imagine having one or
> multiple spring contexts in a java app.
>
> Then having camel context in separate JVMs have the advantage of being in
> totally isolated process, but obviously that requires more resources in
> total. Also having the app split in separate processes is not enough if the
> interaction between these process is synchronous an if losing one JVM
> breaks the whole app. So you have to use something like activemq for the
> processes to interact in asynch and decoupled manner.
>
>
>
> >
> > Note:
> > We have tom-cat web container in our deployment environment.
> > Considering the 'greedy-route' scenario explained above, we are not
> > bundling
> > camel with tom-cat.
> > Is there any provision in tomcat that addresses the 'greedy-route'
> > scenario?
> >
>
> Probably one route per context is too granular. Usually I have around 4-5
> routes per context. These routes work together, share the same resources,
> thread pools, lifecycle, error handlers.
>
> Also having written some good cohesive routes and endpoints externalized
> into properties files, means then you can try to different deployment
> scenarios, deploy all the context together, or split them by changing
> endpoints from direct-vm to activemq for example.
>
> One you reached this level, then there are tools such as fabric8 [2]
> which lets you easily manage and deploy your camel context in various
> containers standalone/tomcat/karaf, ensures that enough containers/JVMs are
> up and running...
>
>
> [1]
> http://www.ofbizian.com/2014/01/masterslave-failover-for-camel-routes.html
> [2] http://fabric8.io/gitbook/requirements.html
>
> HTH,
>
> --
> > View this message in context:
> >
> http://camel.465427.n5.nabble.com/one-context-or-multiple-contexts-tp5754635.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>
>
>
> --
> Bilgin Ibryam
>
> Red Hat, Inc.
> Apache Camel & Apache OFBiz committer
> Blog: ofbizian.com
> Twitter: @bibryam <https://twitter.com/bibryam>
>
> Author of Instant Apache Camel Message Routing
> http://www.amazon.com/dp/1783283475
>



-- 
Matt Sicker <bo...@gmail.com>

Re: one context or multiple contexts?

Posted by Bilgin Ibryam <bi...@gmail.com>.
Inline

On 30 July 2014 11:27, sarveswaran_m <sa...@yahoo.com> wrote:

> We have a bunch of independent routes.
> We run camel in stand-alone mode.
> Ideally, we can run all our routes in a single camel context.
> In such a scenario, a single greedy route consuming excess memory can bring
> down the entire JVM.
> There by, bringing all the routes down.
> Is there any way this can be prevented in camel?
>

If there is a chance that a route brings the whole jvm down and you cannot
afford any down time, your best option is to have another jvm to take over.
Here are few ways to achieve master/slave configuration for camel routes [1]


>
> The alternate is to run each route in a separate context (in a separate
> JVM,
> as a separate process)
> Is it a good idea to run each route as a separate process?
>
How does it compare with running multiple routes from a single context?
> What is the trade-off?
>

First, having one camel context or multipe camel contexts is not very
different as long as they are in the same JVM. Imagine having one or
multiple spring contexts in a java app.

Then having camel context in separate JVMs have the advantage of being in
totally isolated process, but obviously that requires more resources in
total. Also having the app split in separate processes is not enough if the
interaction between these process is synchronous an if losing one JVM
breaks the whole app. So you have to use something like activemq for the
processes to interact in asynch and decoupled manner.



>
> Note:
> We have tom-cat web container in our deployment environment.
> Considering the 'greedy-route' scenario explained above, we are not
> bundling
> camel with tom-cat.
> Is there any provision in tomcat that addresses the 'greedy-route'
> scenario?
>

Probably one route per context is too granular. Usually I have around 4-5
routes per context. These routes work together, share the same resources,
thread pools, lifecycle, error handlers.

Also having written some good cohesive routes and endpoints externalized
into properties files, means then you can try to different deployment
scenarios, deploy all the context together, or split them by changing
endpoints from direct-vm to activemq for example.

One you reached this level, then there are tools such as fabric8 [2]
which lets you easily manage and deploy your camel context in various
containers standalone/tomcat/karaf, ensures that enough containers/JVMs are
up and running...


[1]
http://www.ofbizian.com/2014/01/masterslave-failover-for-camel-routes.html
[2] http://fabric8.io/gitbook/requirements.html

HTH,

--
> View this message in context:
> http://camel.465427.n5.nabble.com/one-context-or-multiple-contexts-tp5754635.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Bilgin Ibryam

Red Hat, Inc.
Apache Camel & Apache OFBiz committer
Blog: ofbizian.com
Twitter: @bibryam <https://twitter.com/bibryam>

Author of Instant Apache Camel Message Routing
http://www.amazon.com/dp/1783283475