Author: asankha
Date: Sun Apr 29 15:21:46 2007
New Revision: 533570

URL: http://svn.apache.org/viewvc?view=rev&rev=533570
Log:
introduce mechanism to tune nhttp performance parameters through system 
properties and/or a nhttp.properties property file
tunes parameters such as thread pool size, worker threads, socket and 
connection timeouts etc

Added:
    
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NHttpConfiguration.java
Modified:
    
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java
    
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOListener.java
    
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java
    
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java

Modified: 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java?view=diff&rev=533570&r1=533569&r2=533570
==============================================================================
--- 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ClientHandler.java
 Sun Apr 29 15:21:46 2007
@@ -68,9 +68,6 @@
     ConfigurationContext cfgCtx = null;
 
     private Executor workerPool = null;
-    private static final int WORKERS_CORE_THREADS = 40;
-    private static final int WORKERS_MAX_THREADS  = 40;
-    private static final long WORKER_KEEP_ALIVE   = 5L;
 
     private static final String REQUEST_BUFFER = "request-buffer";
     private static final String RESPONSE_BUFFER = "response-buffer";
@@ -93,9 +90,13 @@
         this.httpProcessor = getHttpProcessor();
         this.connStrategy = new DefaultConnectionReuseStrategy();
 
+        NHttpConfiguration cfg = NHttpConfiguration.getInstance();
         workerPool = new ThreadPoolExecutor(
-            WORKERS_CORE_THREADS, WORKERS_MAX_THREADS, WORKER_KEEP_ALIVE, 
TimeUnit.SECONDS,
-            new LinkedBlockingQueue(),
+            cfg.getClientCoreThreads(),
+            cfg.getClientMaxThreads(),
+            cfg.getClientKeepalive(), TimeUnit.SECONDS,
+            cfg.getClientQueueLen() == -1 ?
+                new LinkedBlockingQueue() : new 
LinkedBlockingQueue(cfg.getServerQueueLen()),
             new DefaultThreadFactory(new ThreadGroup("Client Worker thread 
group"), "HttpClientWorker"));
     }
 

Modified: 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOListener.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOListener.java?view=diff&rev=533570&r1=533569&r2=533570
==============================================================================
--- 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOListener.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOListener.java
 Sun Apr 29 15:21:46 2007
@@ -75,7 +75,8 @@
     private void startServerEngine(int port) {
         HttpParams params = getServerParameters();
         try {
-            ioReactor = new DefaultListeningIOReactor(2, params);
+            ioReactor = new DefaultListeningIOReactor(
+                NHttpConfiguration.getInstance().getServerIOWorkers(), params);
         } catch (IOException e) {
             log.error("Error starting the IOReactor", e);
         }
@@ -107,11 +108,16 @@
      */
     private HttpParams getServerParameters() {
         HttpParams params = new BasicHttpParams();
+        NHttpConfiguration cfg = NHttpConfiguration.getInstance();
         params
-            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 30000)
-            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
-            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, 
false)
-            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
+            .setIntParameter(HttpConnectionParams.SO_TIMEOUT,
+                cfg.getProperty(HttpConnectionParams.SO_TIMEOUT, 30000))
+            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,
+                cfg.getProperty(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 
1024))
+            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK,
+                cfg.getProperty(HttpConnectionParams.STALE_CONNECTION_CHECK, 
0) == 1)
+            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY,
+                cfg.getProperty(HttpConnectionParams.TCP_NODELAY, 1) == 1)
             .setParameter(HttpProtocolParams.ORIGIN_SERVER, 
"Synapse-HttpComponents-NIO");
         return params;
     }

Modified: 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java?view=diff&rev=533570&r1=533569&r2=533570
==============================================================================
--- 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java
 Sun Apr 29 15:21:46 2007
@@ -114,7 +114,8 @@
 
         HttpParams params = getClientParameters();
         try {
-            ioReactor = new DefaultConnectingIOReactor(2, params);
+            ioReactor = new DefaultConnectingIOReactor(
+                NHttpConfiguration.getInstance().getClientIOWorkers(), params);
         } catch (IOException e) {
             log.error("Error starting the IOReactor", e);
         }
@@ -172,13 +173,19 @@
      * @return the applicable HTTP protocol parameters
      */
     private HttpParams getClientParameters() {
+        NHttpConfiguration cfg = NHttpConfiguration.getInstance();
         HttpParams params = new BasicHttpParams();
         params
-            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 30000)
-            .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000)
-            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
-            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, 
false)
-            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
+            .setIntParameter(HttpConnectionParams.SO_TIMEOUT,
+                cfg.getProperty(HttpConnectionParams.SO_TIMEOUT, 30000))
+            .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT,
+                cfg.getProperty(HttpConnectionParams.CONNECTION_TIMEOUT, 
10000))
+            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,
+                cfg.getProperty(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 
1024))
+            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK,
+                cfg.getProperty(HttpConnectionParams.STALE_CONNECTION_CHECK, 
0) == 1)
+            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY,
+                cfg.getProperty(HttpConnectionParams.TCP_NODELAY, 1) == 1)
             .setParameter(HttpProtocolParams.USER_AGENT, 
"Synapse-HttpComponents-NIO");
         return params;
     }

Added: 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NHttpConfiguration.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NHttpConfiguration.java?view=auto&rev=533570
==============================================================================
--- 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NHttpConfiguration.java
 (added)
+++ 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/NHttpConfiguration.java
 Sun Apr 29 15:21:46 2007
@@ -0,0 +1,130 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.axis2.transport.nhttp;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+import org.apache.http.params.HttpConnectionParams;
+
+import java.util.Properties;
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * Store and manage properties that tune the nhttp transport
+ */
+public class NHttpConfiguration {
+
+    // defaults
+    private static final int WORKERS_CORE_THREADS  = 20;
+    private static final int WORKERS_MAX_THREADS   = 40;
+    private static final int WORKER_KEEP_ALIVE     = 5;
+    private static final int BLOCKING_QUEUE_LENGTH = -1;
+    private static final int IO_WORKER_COUNT = 2;
+
+    // server listener
+    private static final String S_T_CORE     = "snd_t_core";
+    private static final String S_T_MAX      = "snd_t_max";
+    private static final String S_T_ALIVE    = "snd_alive_sec";
+    private static final String S_T_QLEN     = "snd_qlen";
+    private static final String S_IO_WORKERS = "snd_io_threads";
+
+    // client sender
+    private static final String C_T_CORE     = "lst_t_core";
+    private static final String C_T_MAX      = "lst_t_max";
+    private static final String C_T_ALIVE    = "lst_alive_sec";
+    private static final String C_T_QLEN     = "lst_qlen";
+    private static final String C_IO_WORKERS = "lst_io_threads";
+
+    private static final Log log = LogFactory.getLog(NHttpConfiguration.class);
+    private static NHttpConfiguration _instance = new NHttpConfiguration();
+    private Properties props = new Properties();
+
+    private NHttpConfiguration() {
+        try {
+            
props.load(getClass().getClassLoader().getResourceAsStream("nhttp.properties"));
+        } catch (Exception ignore) {}
+    }
+
+    public static NHttpConfiguration getInstance() {
+        return _instance;
+    }
+
+    public int getServerCoreThreads() {
+        return getProperty(S_T_CORE, WORKERS_CORE_THREADS);
+    }
+
+    public int getServerMaxThreads() {
+        return getProperty(S_T_MAX, WORKERS_MAX_THREADS);
+    }
+
+    public int getServerKeepalive() {
+        return getProperty(S_T_ALIVE, WORKER_KEEP_ALIVE);
+    }
+
+    public int getServerQueueLen() {
+        return getProperty(S_T_QLEN, BLOCKING_QUEUE_LENGTH);
+    }
+
+    public int getServerIOWorkers() {
+        return getProperty(S_IO_WORKERS, IO_WORKER_COUNT);
+    }
+
+
+    public int getClientCoreThreads() {
+        return getProperty(C_T_CORE, WORKERS_CORE_THREADS);
+    }
+
+    public int getClientMaxThreads() {
+        return getProperty(C_T_MAX, WORKERS_MAX_THREADS);
+    }
+
+    public int getClientKeepalive() {
+        return getProperty(C_T_ALIVE, WORKER_KEEP_ALIVE);
+    }
+
+    public int getClientQueueLen() {
+        return getProperty(C_T_QLEN, BLOCKING_QUEUE_LENGTH);
+    }
+
+    public int getClientIOWorkers() {
+        return getProperty(C_IO_WORKERS, IO_WORKER_COUNT);
+    }
+
+    /**
+     * Get properties that tune nhttp transport. Preference to system 
properties
+     * @param name name of the system/config property
+     * @param def default value to return if the property is not set
+     * @return the value of the property to be used
+     */
+    public int getProperty(String name, int def) {
+        String val = System.getProperty(name);
+        if (val == null) {
+            val = props.getProperty(name);
+        }
+
+        if (val != null && Integer.valueOf(val).intValue() > 0) {
+            log.debug("Using nhttp tuning parameter : " + name + " = " + val);
+            return Integer.valueOf(val).intValue();
+        }        
+        return def;
+    }
+
+}

Modified: 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
URL: 
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java?view=diff&rev=533570&r1=533569&r2=533570
==============================================================================
--- 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
 (original)
+++ 
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/ServerHandler.java
 Sun Apr 29 15:21:46 2007
@@ -69,9 +69,6 @@
 
     /** the thread pool to process requests */
     private Executor workerPool = null;
-    private static final int WORKERS_CORE_THREADS = 40;
-    private static final int WORKERS_MAX_THREADS  = 40;
-    private static final long WORKER_KEEP_ALIVE   = 5L;
 
     private static final String REQUEST_SINK_CHANNEL = "request-sink-channel";
     private static final String RESPONSE_SOURCE_CHANNEL = 
"response-source-channel";
@@ -88,9 +85,13 @@
         this.httpProcessor = getHttpProcessor();
         this.connStrategy = new DefaultConnectionReuseStrategy();
 
+        NHttpConfiguration cfg = NHttpConfiguration.getInstance();
         this.workerPool = new ThreadPoolExecutor(
-            WORKERS_CORE_THREADS, WORKERS_MAX_THREADS, WORKER_KEEP_ALIVE, 
TimeUnit.SECONDS,
-            new LinkedBlockingQueue(),
+            cfg.getServerCoreThreads(),
+            cfg.getServerMaxThreads(),
+            cfg.getServerKeepalive(), TimeUnit.SECONDS,
+            cfg.getServerQueueLen() == -1 ?
+                new LinkedBlockingQueue() : new 
LinkedBlockingQueue(cfg.getServerQueueLen()),
             new DefaultThreadFactory(new ThreadGroup("Server Worker thread 
group"), "HttpServerWorker"));
     }
 
@@ -137,7 +138,7 @@
         } catch (IOException e) {
             handleException("Error processing request received for : " +
                 request.getRequestLine().getUri(), e, conn);
-        } catch (RejectedExecutionException e) {
+        } catch (Exception e) {
             handleException("Error processing request received for : " +
                 request.getRequestLine().getUri(), e, conn);
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to