Camel 2.3 - ThreadPool ConfigurationPage edited by Claus IbsenDesign Notes for ThreadPool ConfigurationCAMEL-1588 is the ticket for a new and improved thread pool configuration for Apache Camel. Its intended for Camel 2.3. ScopeCamel uses thread pool in various places such as EIP patterns, Components, Async API and whatnot. The aim is to improved and allow easier to configure those thread pools in a more streamlined manner. The goal is to offer both a fine grained configuration where you can tweak individual pools and have more coarse grained configuration with fallback to global settings etc. Outside scopeSome components provides their own thread pool configuration and management which Camel of course cannot and should not try to tailor with. For example Jetty is such an example. Usages of thread pools in CamelCurrently Camel uses thread pools in camel-core in the following areas:
Existing configurationYou can configure the thread pool using the setExecutorService setter methods that usually exists on those places where its in use. Some EIP patterns offer a executorServiceRef option to refer to some pool to be looked up in the Registry. We should ensure all EIPs can be configured to use a custom thread pool in a nice and easy way. DONE Using default ThreadPoolsWe should use CachedThreadPool from the JDK Core as its the best general purpose pool for many short lived tasks, which is what Camel really does. Processing many messages in a short live. DONE Only used SingleExecutorService for background tasks, and ScheduledExecutorService for scheduled tasks DONE ThreadPool scopeIt should be possible to configure a thread pool on either per CamelContext level or per Route level, such as you can do with AutoStartup and the likes. Thread pool configuration by rulesIt should be possible to to define a set of rules which matches which thread pool a given source should use. A ruleset something like this: <threadPoolRule route="*" source="Aggregator" executorServiceRef="myAggPool"/> <threadPoolRule route="*" source="To" executorServiceRef="mySendPool"/> <threadPoolRule route="route3" source="*" executorServiceRef="myRoute3Pool"/>
And it should validate that only one defaultProfile=true can be set. Status: DONE The problem with shutdown and restarting poolsThe ExecutorService API does not allow to restart a thread pool, which is PITA. So we need to find a better strategy for stopping vs. shutdown. We may have to only shutdown thread pools if CamelContext is stopping. And then if end user stop a route from JMX we can keep the thread pool around. We have introduced a ShutdownableService to expose a shutdown method which services can implement for their shutdown logic. By letting Camel keep track of created thread pool, then Camel knows which pools shutdown when its stopping. Then the need for doShutdown is not as apparent as before, but its good to have this state in the lifecycles as well, for future needs. Status: DONE The problem with Component, EndpointThe DefaultComponent and DefaultEndpoint exposes API to get an ExecutorService. We should remove these API as you should use ExecutorServiceStrategy from CamelContext to obtain a thread pool. DONE Managed thread poolCheck whether the thread pools is managed by default and avail in JConsole. If not we should probably at least expose some read-only data about the pools. Spring Factory for creating custom poolsCreate a Spring XML DSL for defining thread pools using custom options such as corePoolSize, maxPoolSize, keepAlive, thread name etc. DONE Pluggable ExecutorService SPIWe need a org.apache.camel.spi.ExeuctorServieStrategy which is pluggable so end users can plugin their own strategy how to create thread pools. They can leverage a WorkManager API from J2EE server etc. DONE Customizable thread nameWe should offer a simple pattern syntax so end users can customize the pattern the thread name is created with: eg Something like: Camel Thread ${counter} - ${name}. Where counter and suffix is dynamic parameters. The counter is an unique incrementing thread counter. And name is provided from the source which as a way to name thread, such as a seda endpoint uri. DONE EIP should mandate an ExecutorServiceIf the EIPS which leverages a ExecutorService, mandates its being created and passed to it, we can enforce creating/lookup the pool during route creation, which allows us to have the route information as well, so we know which routes creates which pools. By passing in null we loose this opportunity. Let Camel keep track of created poolsUsing the DefaultExecutorServiceStrategy we can let Camel keep track of the created pools, and thus also it can shutdown those when CamelContext is shutting down. Then Camel is handling the lifecycle for the pools it creates. And if you pass in a thread pool from an external system then you manage that lifecycle. Camel will in those cases not shut it down. DONE Sensible defaultsThe CachedExecutorService by the JDK is maybe a bit aggressive as its unbounded thread pool which essentially can create 1000s of threads if the sever is not busy. But end users may want to have a reasonable max size, lets say 100. So we should offer some sort of rule which you can configure what the default settings should be for thread pools created by Camel. DONE Rejection policyWe should add configuration about rejection policies for new tasks submitted to a pool. The JDK has options for ABORT, RUN, WAIT, DISCARD etc. DONE
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence
- [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration confluence