You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by thestubborncamel <ra...@gmail.com> on 2012/01/21 19:11:46 UTC

Threading Model in Camel

Folks -

I read the threading model documentation, but i am still a bit unclear.

Here is a Question (or may be two): 

Say, I have a synchronous flow
http-from-endpoint -> bean processors -> to-end-point -> one or more bean
processors -> end-http-invocation

1. does jetty http thread dispatch the message to a camel thread pool to run
thru the route (bean processors)? or is the execution happening on the jetty
thread?

2. Where would one configure the thread pool size so I can tune to the
demands of my application?

Thanks for any pointers..

--
View this message in context: http://camel.465427.n5.nabble.com/Threading-Model-in-Camel-tp5163081p5163081.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Threading Model in Camel

Posted by Babak Vahdat <ba...@swissonline.ch>.

Am 23.01.12 14:56 schrieb "thestubborncamel" unter
<ra...@gmail.com>:

>Thanks for that clarification again. that helps a lot.
>
>Extending this discussion a bit -
>
>If I were to generalize it, the ³consumer² thread at the appropriate
>from-endpoint-transport is what is used to complete the route
>execution.
>
>i.e. if incoming requests is a http(jetty server) endpoint, route
>execution is done on the consumer threads managed by jetty. (and you
>would have to configure those thread pools in
>'org.eclipse.jetty.util.thread.ThreadPool' and not through the managed
>thread pools that Camel creates.)

Right!

>
>Likewise, for JMS transport, the route is completed on the consumer
>thread of the JMS consumer. The concurrency or thread pool for JMS
>from-endpoint is configured using  jms:MyQueue?concurrentConsumers=NN.

Also in case of JMS concurrentConsumers it's similar to Jetty as well,
that's this option is delegated to Spring JMS
DefaultMessageListenerContainer which creates it's *own* worker threads
for that option. So that Camel's managed thread pool(s) doesn't effect
anything here at all.

>
>So - then - seems like any camel managed thread pools are used
>primarily for parallel processing of beans or async handling within
>the camel route.

Yes, like the SEDA component making use of the Camel's managed thread
pools which is simply leveraging of the JDK concurrency API.

>
>Woud that be a fair statement? any corrections or further thoughts?

And you can also hook in your custom ThreadPoolFactory [1] in case you
intend not
to make use of the leveraged JDK concurrency API. For example in a JEE
setup an implementation of yours could make use of the WorkerManager [2]
API.

[1] 
http://camel.apache.org/advanced-configuration-of-camelcontext-using-spring
.html
[2] 
http://docs.oracle.com/javaee/6/api/javax/resource/spi/work/WorkManager.htm
l


>
>On 1/22/12, Babak Vahdat [via Camel]
><ml...@n5.nabble.com> wrote:
>>
>>
>> Yes!
>>
>> The processing of the incoming requests by Jetty are done inside threads
>> managed by the thread pools of the type
>> 'org.eclipse.jetty.util.thread.ThreadPool' and not through the managed
>> thread pools that Camel creates.
>>
>> Babak
>>
>> _______________________________________________
>> If you reply to this email, your message will be added to the discussion
>> below:
>> 
>>http://camel.465427.n5.nabble.com/Threading-Model-in-Camel-tp5163081p5163
>>797.html
>>
>> To unsubscribe from Threading Model in Camel, visit
>> 
>>http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscr
>>ibe_by_code&node=5163081&code=cmFtYXJhZ2hhdmFuQGdtYWlsLmNvbXw1MTYzMDgxfC0
>>xNTUxNzMzMDM0
>
>
>-- 
>Rama Raghavan
>Mobile: (972) 273-9875
>
>
>--
>View this message in context:
>http://camel.465427.n5.nabble.com/Threading-Model-in-Camel-tp5163081p51661
>27.html
>Sent from the Camel - Users mailing list archive at Nabble.com.



Re: Threading Model in Camel

Posted by thestubborncamel <ra...@gmail.com>.
Thanks for that clarification again. that helps a lot.

Extending this discussion a bit -

If I were to generalize it, the “consumer” thread at the appropriate
from-endpoint-transport is what is used to complete the route
execution.

i.e. if incoming requests is a http(jetty server) endpoint, route
execution is done on the consumer threads managed by jetty. (and you
would have to configure those thread pools in
'org.eclipse.jetty.util.thread.ThreadPool' and not through the managed
thread pools that Camel creates.)

Likewise, for JMS transport, the route is completed on the consumer
thread of the JMS consumer. The concurrency or thread pool for JMS
from-endpoint is configured using  jms:MyQueue?concurrentConsumers=NN.

So - then - seems like any camel managed thread pools are used
primarily for parallel processing of beans or async handling within
the camel route.

Woud that be a fair statement? any corrections or further thoughts?

On 1/22/12, Babak Vahdat [via Camel]
<ml...@n5.nabble.com> wrote:
>
>
> Yes!
>
> The processing of the incoming requests by Jetty are done inside threads
> managed by the thread pools of the type
> 'org.eclipse.jetty.util.thread.ThreadPool' and not through the managed
> thread pools that Camel creates.
>
> Babak
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/Threading-Model-in-Camel-tp5163081p5163797.html
>
> To unsubscribe from Threading Model in Camel, visit
> http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5163081&code=cmFtYXJhZ2hhdmFuQGdtYWlsLmNvbXw1MTYzMDgxfC0xNTUxNzMzMDM0


-- 
Rama Raghavan
Mobile: (972) 273-9875


--
View this message in context: http://camel.465427.n5.nabble.com/Threading-Model-in-Camel-tp5163081p5166127.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Threading Model in Camel

Posted by Babak Vahdat <ba...@swissonline.ch>.
Yes!

The processing of the incoming requests by Jetty are done inside threads
managed by the thread pools of the type
'org.eclipse.jetty.util.thread.ThreadPool' and not through the managed
thread pools that Camel creates.

Babak

--
View this message in context: http://camel.465427.n5.nabble.com/Threading-Model-in-Camel-tp5163081p5163797.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Threading Model in Camel

Posted by thestubborncamel <ra...@gmail.com>.
Thanks for a quick response. 

So, just to confirm - message processing is handled on the consumer thread of the transport (http jetty server)        . i.e.,processing is not dispatched to any managed thread pool , right?



On Jan 21, 2012, at 1:29 PM, "Babak Vahdat [via Camel]" <ml...@n5.nabble.com> wrote:

> Hi, 
> 
> The Jetty consumer (HTTP-Server) of the camel-jetty component makes use of the implementations of [1] to process the incoming HTTP request. 
> 
> Take a look at Component Options [2] for the possible customizations of threadPool/minThreads/maxThreads etc. 
> 
> And you can both configure your own threadPool both in Java or Xml. As an example in Xml you would do something like: 
> 
>      <bean id="myThreadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
>        customize it the way you want to have it 
>      </bean>
> 
>     <bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent">
>         <property name="threadPool" ref="myThreadPool"/>
>     </bean>
> 
> And in case of Java you can wire exactly the same way as above through "coding". However IMHO it's better/easier to wire the objects in Xml (Spring) and code the Camel routes in Java DSL. However this is just a matter of personal  taste. 
> 
> [1] http://download.eclipse.org/jetty/7.5.4.v20111024/apidocs/org/eclipse/jetty/util/thread/ThreadPool.html
> [2] http://camel.apache.org/jetty
> 
> Babak 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://camel.465427.n5.nabble.com/Threading-Model-in-Camel-tp5163081p5163179.html
> To unsubscribe from Threading Model in Camel, click here.
> NAML


--
View this message in context: http://camel.465427.n5.nabble.com/Threading-Model-in-Camel-tp5163081p5163396.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Threading Model in Camel

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi,

The Jetty consumer (HTTP-Server) of the camel-jetty component makes use of
the implementations of [1] to process the incoming HTTP request.

Take a look at Component Options [2] for the possible customizations of
threadPool/minThreads/maxThreads etc.

And you can both configure your own threadPool both in Java or Xml. As an
example in Xml you would do something like:

     <bean id="myThreadPool"
class="org.eclipse.jetty.util.thread.QueuedThreadPool">
       customize it the way you want to have it
     </bean>

    <bean id="jetty"
class="org.apache.camel.component.jetty.JettyHttpComponent">
        <property name="threadPool" ref="myThreadPool"/>
    </bean>

And in case of Java you can wire exactly the same way as above through
"coding". However IMHO it's better/easier to wire the objects in Xml
(Spring) and code the Camel routes in Java DSL. However this is just a
matter of personal  taste.

[1]
http://download.eclipse.org/jetty/7.5.4.v20111024/apidocs/org/eclipse/jetty/util/thread/ThreadPool.html
[2] http://camel.apache.org/jetty

Babak

--
View this message in context: http://camel.465427.n5.nabble.com/Threading-Model-in-Camel-tp5163081p5163179.html
Sent from the Camel - Users mailing list archive at Nabble.com.