You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/05/13 09:07:41 UTC

[2/3] camel git commit: CAMEL-8771 Add MaxChannelMemorySize and MaxTotalMemorySize for OrderedMemoryAwareThreadPoolExecutor

CAMEL-8771 Add MaxChannelMemorySize and MaxTotalMemorySize for OrderedMemoryAwareThreadPoolExecutor


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a86f22b6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a86f22b6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a86f22b6

Branch: refs/heads/master
Commit: a86f22b6ba400946f120f0c7c977bc39fbfa9e66
Parents: 9facd03
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed May 13 14:52:21 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed May 13 15:06:51 2015 +0800

----------------------------------------------------------------------
 .../camel/component/netty/NettyComponent.java   |  7 ++++++-
 .../component/netty/NettyConfiguration.java     | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a86f22b6/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
index ac622d0..e1be1c2 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
@@ -138,10 +138,15 @@ public class NettyComponent extends UriEndpointComponent {
         // replies in the expected order. eg this is required by TCP.
         // and use a Camel thread factory so we have consistent thread namings
         // we should use a shared thread pool as recommended by Netty
+        
+        // NOTE: if we don't specify the MaxChannelMemorySize and MaxTotalMemorySize, the thread pool
+        // could eat up all the heap memory when the tasks are added very fast
+        
         String pattern = getCamelContext().getExecutorServiceManager().getThreadNamePattern();
         ThreadFactory factory = new CamelThreadFactory(pattern, "NettyOrderedWorker", true);
         return new OrderedMemoryAwareThreadPoolExecutor(getMaximumPoolSize(),
-                0L, 0L, 30, TimeUnit.SECONDS, factory);
+                configuration.getMaxChannelMemorySize(), configuration.getMaxTotalMemorySize(),
+                30, TimeUnit.SECONDS, factory);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/a86f22b6/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
index 700fa0a..ca06845 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
@@ -96,6 +96,10 @@ public class NettyConfiguration extends NettyServerBootstrapConfiguration implem
     private boolean clientMode;
     @UriParam
     private boolean useChannelBuffer;
+    @UriParam(defaultValue = "" + 10 * 1024 * 1024L)
+    private long maxChannelMemorySize = 10 * 1024 * 1024L; 
+    @UriParam(defaultValue = "" + 200 * 1024 * 1024L)
+    private long maxTotalMemorySize = 200 * 1024 * 1024L;
 
     /**
      * Returns a copy of this configuration
@@ -476,6 +480,22 @@ public class NettyConfiguration extends NettyServerBootstrapConfiguration implem
         this.useChannelBuffer = useChannelBuffer;
     }
 
+    public long getMaxChannelMemorySize() {
+        return maxChannelMemorySize;
+    }
+
+    public void setMaxChannelMemorySize(long maxChannelMemorySize) {
+        this.maxChannelMemorySize = maxChannelMemorySize;
+    }
+
+    public long getMaxTotalMemorySize() {
+        return maxTotalMemorySize;
+    }
+
+    public void setMaxTotalMemorySize(long maxTotalMemorySize) {
+        this.maxTotalMemorySize = maxTotalMemorySize;
+    }
+
     private static <T> void addToHandlersList(List<T> configured, List<T> handlers, Class<T> handlerType) {
         if (handlers != null) {
             for (T handler : handlers) {