You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2007/11/02 13:15:49 UTC

svn commit: r591312 - in /mina/trunk/core/src/main/java/org/apache/mina/filter/traffic: ReadThrottleFilter.java ReadThrottleFilterChainBuilder.java WriteThrottleFilter.java WriteThrottlePolicy.java

Author: trustin
Date: Fri Nov  2 05:15:47 2007
New Revision: 591312

URL: http://svn.apache.org/viewvc?rev=591312&view=rev
Log:
Related issue: DIRMINA-302 (Unbounded nature of writeRequestQueue can cause OutOfMemoryException)
* More documentation

Modified:
    mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilter.java
    mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilterChainBuilder.java
    mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottleFilter.java
    mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottlePolicy.java

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilter.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilter.java?rev=591312&r1=591311&r2=591312&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilter.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilter.java Fri Nov  2 05:15:47 2007
@@ -26,7 +26,8 @@
 
 /**
  * An {@link IoFilter} interface that provides access to the properties related
- * with inflow traffic control.  Please build the {@link IoFilterChain} with
+ * with incoming traffic control to prevent a unwanted {@link OutOfMemoryError}
+ * under heavy load.  Please build the {@link IoFilterChain} with
  * {@link ReadThrottleFilterChainBuilder} to access this filter.  Once properly
  * installed, you can access this filter using the following code:
  * <pre><code>

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilterChainBuilder.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilterChainBuilder.java?rev=591312&r1=591311&r2=591312&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilterChainBuilder.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/ReadThrottleFilterChainBuilder.java Fri Nov  2 05:15:47 2007
@@ -19,6 +19,7 @@
  */
 package org.apache.mina.filter.traffic;
 
+import java.util.concurrent.Executor;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.mina.common.AttributeKey;
@@ -34,7 +35,8 @@
 
 /**
  * An {@link IoFilterChainBuilder} that configures an {IoFilterChain} or
- * {@link DefaultIoFilterChainBuilder} to control inflow traffic.
+ * {@link DefaultIoFilterChainBuilder} to control incoming traffic to
+ * prevent a unwanted {@link OutOfMemoryError} under heavy load.
  * <p>
  * The filters that this builder inserts will automatically disable reads
  * on an {@link IoSession} once the data batched for that session in the

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottleFilter.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottleFilter.java?rev=591312&r1=591311&r2=591312&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottleFilter.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottleFilter.java Fri Nov  2 05:15:47 2007
@@ -19,47 +19,25 @@
  */
 package org.apache.mina.filter.traffic;
 
+import org.apache.mina.common.IoFilter;
 import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoService;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionLogger;
 import org.apache.mina.common.WriteException;
 import org.apache.mina.common.WriteRequest;
 
 /**
- * This filter will turn the asynchronous write method in to a blocking send when there are more than
- * the prescribed number of messages awaiting sending. It should be used in conjunction with the
- * {@link ReadThrottleFilterBuilder} on a server as the blocking writes will allow the read thread to
- * cause an Out of Memory exception due to a back log of unprocessed messages.
- *
- * This is should only be viewed as a temporary work around for DIRMINA-302.
- *
- * A true solution should not be implemented as a filter as this issue will always occur. On a machine
- * where the network is slower than the local producer.
- *
- * Suggested improvement is to allow implementation of policices on what to do when buffer is full.
- *
- *  They could be:
- *          Block - As this does
- *          Wait on a given Future - to drain more of the queue.. in essence this filter with high/low watermarks
- *          Throw Exception - through the client write() method to allow them to get immediate feedback on buffer state
- * 
- * <p/>
- * <p>Usage:
- * <p/>
- * <pre><code>
- * DefaultFilterChainBuilder builder = ...
- * WriteBufferLimitFilterBuilder filter = new WriteBufferLimitFilterBuilder();
- * filter.attach( builder );
- * </code></pre>
- * <p/>
- * or
- * <p/>
- * <pre><code>
- * IoFilterChain chain = ...
- * WriteBufferLimitFilterBuilder filter = new WriteBufferLimitFilterBuilder();
- * filter.attach( chain );
- * </code></pre>
- *
+ * An {@link IoFilter} that throttles outgoing traffic to prevent a unwanted
+ * {@link OutOfMemoryError} under heavy load.
+ * <p>
+ * This filter will automatically enforce the specified {@link WriteThrottlePolicy}
+ * when the {@link IoSession#getScheduledWriteBytes() localScheduledWriteBytes},
+ * {@link IoSession#getScheduledWriteMessages() localScheduledWriteMessages},
+ * {@link IoService#getScheduledWriteBytes() globalScheduledWriteBytes} or
+ * {@link IoService#getScheduledWriteMessages() globalScheduledWriteMessages}
+ * exceeds the specified limit values.
+
  * @author The Apache MINA Project (dev@mina.apache.org)
  * @version $Rev$, $Date$
  */
@@ -78,14 +56,26 @@
     private volatile int globalMaxScheduledWriteMessages;
     private volatile long globalMaxScheduledWriteBytes;
     
+    /**
+     * Creates a new instance with the default policy
+     * ({@link WriteThrottlePolicy#LOG}) and limit values.
+     */
     public WriteThrottleFilter() {
         this(WriteThrottlePolicy.LOG);
     }
     
+    /**
+     * Creates a new instance with the specified <tt>policy</tt> and the
+     * default limit values.
+     */
     public WriteThrottleFilter(WriteThrottlePolicy policy) {
         this(policy, 4096, 65536, 131072, 1048576 * 128);
     }
     
+    /**
+     * Creates a new instance with the default policy
+     * ({@link WriteThrottlePolicy#LOG}) and the specified limit values.
+     */
     public WriteThrottleFilter(
             int localMaxScheduledWriteMessages, long localMaxScheduledWriteBytes,
             int globalMaxScheduledWriteMessages, long globalMaxScheduledWriteBytes) {
@@ -94,6 +84,10 @@
              globalMaxScheduledWriteMessages, globalMaxScheduledWriteBytes);
     }
     
+    /**
+     * Creates a new instance with the specified <tt>policy</tt> and limit
+     * values.
+     */
     public WriteThrottleFilter(
             WriteThrottlePolicy policy,
             int localMaxScheduledWriteMessages, long localMaxScheduledWriteBytes,

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottlePolicy.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottlePolicy.java?rev=591312&r1=591311&r2=591312&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottlePolicy.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/WriteThrottlePolicy.java Fri Nov  2 05:15:47 2007
@@ -35,6 +35,8 @@
     OFF,
     /**
      * Log a warning message, but doesn't limit anything.
+     * The warning message is logged at most every 3 seconds to avoid
+     * log flooding.
      */
     LOG,
     /**