You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by ru...@apache.org on 2007/10/17 04:59:38 UTC
svn commit: r585336 - in /webservices/synapse/trunk/java:
modules/core/src/main/java/org/apache/synapse/
modules/core/src/main/java/org/apache/synapse/config/
modules/core/src/main/java/org/apache/synapse/core/axis2/
modules/core/src/main/java/org/apac...
Author: ruwan
Date: Tue Oct 16 19:59:35 2007
New Revision: 585336
URL: http://svn.apache.org/viewvc?rev=585336&view=rev
Log:
Adding synapse.properties and the relevant logic for that to effective in Synapse Threadpool optimization
Added:
webservices/synapse/trunk/java/repository/conf/synapse.properties
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/concurrent/SynapseThreadPool.java
webservices/synapse/trunk/java/src/main/bin/synapse.sh
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=585336&r1=585335&r2=585336&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java Tue Oct 16 19:59:35 2007
@@ -79,8 +79,12 @@
/** The name of the system property that will hold the Synapse home directory */
public static final String SYNAPSE_HOME = "synapse.home";
+ /** The default synapse.properties file path */
+ public static final String DEFAULT_PROP_PATH = "synapse.properties";
/** The name of the system property used to specify/override the synapse config XML location */
public static final String SYNAPSE_XML = "synapse.xml";
+ /** The name of the system property used to specify/override the synapse properties location */
+ public static final String SYNAPSE_PROPERTIES = "synapse.properties";
//- Synapse Message Context Properties -
/** The Synapse MC property name that holds the name of the Proxy service thats handling it */
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=585336&r1=585335&r2=585336&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java Tue Oct 16 19:59:35 2007
@@ -72,6 +72,9 @@
*/
private Map localRegistry = new HashMap();
+ /** Holds the synapse properties */
+ private Properties properties = new Properties();
+
/**
* This will provide the timer deamon object for the sheduled tasks.
*/
@@ -620,6 +623,44 @@
*/
public void addStartup(Startup startup) {
startups.put(startup.getName(), startup);
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Properties properties) {
+ this.properties = properties;
+ }
+
+ public String getProperty(String propKey, String def) {
+ String val = System.getProperty(propKey);
+ if (val == null) {
+ val = properties.getProperty(propKey);
+ }
+
+ if (val != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Using synapse tuning parameter : " + propKey + " = " + val);
+ }
+ return val;
+ }
+ return def;
+ }
+
+ public String getProperty(String propKey) {
+ String val = System.getProperty(propKey);
+ if (val == null) {
+ val = properties.getProperty(propKey);
+ }
+
+ if (val != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Using synapse tuning parameter : " + propKey + " = " + val);
+ }
+ return val;
+ }
+ return null;
}
/**
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java?rev=585336&r1=585335&r2=585336&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java Tue Oct 16 19:59:35 2007
@@ -31,6 +31,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
/**
* Builds a Synapse Configuration model with a given input
@@ -73,6 +74,7 @@
= XMLConfigurationBuilder.getConfiguration(new FileInputStream(configFile));
log.info("Loaded Synapse configuration from : " + configFile);
synCfg.setPathToConfigFile(new File(configFile).getAbsolutePath());
+ loadSynapseProperties(synCfg);
return synCfg;
} catch (FileNotFoundException fnf) {
@@ -81,6 +83,20 @@
handleException("Could not initialize Synapse : " + e.getMessage(), e);
}
return null;
+ }
+
+ private static void loadSynapseProperties(SynapseConfiguration synCfg) {
+ String props = System.getProperty(SynapseConstants.SYNAPSE_PROPERTIES);
+ if (props == null) {
+ props = SynapseConstants.DEFAULT_PROP_PATH;
+ }
+ try {
+ synCfg.getProperties().load(Thread.currentThread().getContextClassLoader().getResourceAsStream(props));
+ } catch (Exception e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Unable to load synapse properties", e);
+ }
+ }
}
private static void handleException(String msg, Exception e) {
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java?rev=585336&r1=585335&r2=585336&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java Tue Oct 16 19:59:35 2007
@@ -56,13 +56,39 @@
/** The StatisticsCollector object */
private StatisticsCollector statisticsCollector;
- public Axis2SynapseEnvironment() {
- this.executorService = new SynapseThreadPool();
+ public Axis2SynapseEnvironment(SynapseConfiguration synCfg) {
+
+ int coreThreads = SynapseThreadPool.SYNAPSE_CORE_THREADS;
+ int maxThreads = SynapseThreadPool.SYNAPSE_MAX_THREADS;
+ long keepAlive = SynapseThreadPool.SYNAPSE_KEEP_ALIVE;
+ int qlength = SynapseThreadPool.SYNAPSE_THREAD_QLEN;
+
+ try {
+ qlength = Integer.parseInt(synCfg.getProperty(SynapseThreadPool.SYN_THREAD_QLEN));
+ } catch (Exception ignore) {}
+
+ try {
+ coreThreads = Integer.parseInt(synCfg.getProperty(SynapseThreadPool.SYN_THREAD_CORE));
+ } catch (Exception ignore) {}
+
+ try {
+ maxThreads = Integer.parseInt(synCfg.getProperty(SynapseThreadPool.SYN_THREAD_MAX));
+ } catch (Exception ignore) {}
+
+ try {
+ keepAlive = Long.parseLong(synCfg.getProperty(SynapseThreadPool.SYN_THREAD_ALIVE));
+ } catch (Exception ignore) {}
+
+ this.executorService = new SynapseThreadPool(coreThreads, maxThreads, keepAlive, qlength,
+ synCfg.getProperty(SynapseThreadPool.SYN_THREAD_GROUP,
+ SynapseThreadPool.SYNAPSE_THREAD_GROUP),
+ synCfg.getProperty(SynapseThreadPool.SYN_THREAD_IDPREFIX,
+ SynapseThreadPool.SYNAPSE_THREAD_ID_PREFIX));
}
public Axis2SynapseEnvironment(ConfigurationContext cfgCtx,
SynapseConfiguration synapseConfig) {
- this();
+ this(synapseConfig);
this.configContext = cfgCtx;
this.synapseConfig = synapseConfig;
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/concurrent/SynapseThreadPool.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/concurrent/SynapseThreadPool.java?rev=585336&r1=585335&r2=585336&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/concurrent/SynapseThreadPool.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/concurrent/SynapseThreadPool.java Tue Oct 16 19:59:35 2007
@@ -19,6 +19,8 @@
package org.apache.synapse.util.concurrent;
+import org.apache.synapse.config.SynapseConfiguration;
+
import java.util.concurrent.*;
/**
@@ -27,18 +29,20 @@
public class SynapseThreadPool extends ThreadPoolExecutor {
// default values
- private static final int SYNAPSE_CORE_THREADS = 20;
- private static final int SYNAPSE_MAX_THREADS = 100;
- private static final int SYNAPSE_KEEP_ALIVE = 5;
- private static final int BLOCKING_QUEUE_LENGTH = -1;
- private static final String SYNAPSE_THREAD_GROUP = "synapse-thread-group";
- private static final String SYNAPSE_THREAD_ID_PREFIX = "SynapseWorker";
+ public static final int SYNAPSE_CORE_THREADS = 20;
+ public static final int SYNAPSE_MAX_THREADS = 100;
+ public static final int SYNAPSE_KEEP_ALIVE = 5;
+ public static final int SYNAPSE_THREAD_QLEN = 10;
+ public static final String SYNAPSE_THREAD_GROUP = "synapse-thread-group";
+ public static final String SYNAPSE_THREAD_ID_PREFIX = "SynapseWorker";
// property keys
- private static final String SYN_THREAD_CORE = "syn_t_core";
- private static final String SYN_THREAD_MAX = "syn_t_max";
- private static final String SYN_THREAD_ALIVE = "syn_alive_sec";
- private static final String SYN_THREAD_QLEN = "syn_qlen";
+ public static final String SYN_THREAD_CORE = "synapse.threads.core";
+ public static final String SYN_THREAD_MAX = "synapse.threads.max";
+ public static final String SYN_THREAD_ALIVE = "synapse.threads.keepalive";
+ public static final String SYN_THREAD_QLEN = "synapse.threads.qlen";
+ public static final String SYN_THREAD_GROUP = "synapse.threads.group";
+ public static final String SYN_THREAD_IDPREFIX = "synapse.threads.idprefix";
/**
* Constructor for the Synapse thread poll
@@ -63,5 +67,23 @@
public SynapseThreadPool() {
this(SYNAPSE_CORE_THREADS, SYNAPSE_MAX_THREADS, SYNAPSE_KEEP_ALIVE,
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ }
+
+ /**
+ * Constructor for the SynapseThreadPool
+ *
+ * @param corePoolSize - number of threads to keep in the pool, even if they are idle
+ * @param maxPoolSize - the maximum number of threads to allow in the pool
+ * @param keepAliveTime - this is the maximum time that excess idle threads will wait
+ * for new tasks before terminating.
+ * @param qlen - Thread Blocking Queue length
+ * @param threadGroup - ThreadGroup name
+ * @param threadIdPrefix - Thread id prefix
+ */
+ public SynapseThreadPool(int corePoolSize, int maxPoolSize, long keepAliveTime, int qlen,
+ String threadGroup, String threadIdPrefix) {
+ super(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<Runnable>(qlen),
+ new SynapseThreadFactory(new ThreadGroup(threadGroup), threadIdPrefix));
}
}
Added: webservices/synapse/trunk/java/repository/conf/synapse.properties
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/repository/conf/synapse.properties?rev=585336&view=auto
==============================================================================
--- webservices/synapse/trunk/java/repository/conf/synapse.properties (added)
+++ webservices/synapse/trunk/java/repository/conf/synapse.properties Tue Oct 16 19:59:35 2007
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+synapse.threads.core = 20
+synapse.threads.max = 100
+synapse.threads.keepalive = 5
+synapse.threads.qlen = 10
+synapse.threads.group = synapse-thread-group
+synapse.threads.idprefix = SynapseWorker
Modified: webservices/synapse/trunk/java/src/main/bin/synapse.sh
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/src/main/bin/synapse.sh?rev=585336&r1=585335&r2=585336&view=diff
==============================================================================
--- webservices/synapse/trunk/java/src/main/bin/synapse.sh (original)
+++ webservices/synapse/trunk/java/src/main/bin/synapse.sh Tue Oct 16 19:59:35 2007
@@ -95,7 +95,7 @@
do
SYNAPSE_CLASSPATH=$SYNAPSE_CLASSPATH:$f
done
-SYNAPSE_CLASSPATH=$JAVA_HOME/lib/tools.jar:$SYNAPSE_CLASSPATH:$CLASSPATH
+SYNAPSE_CLASSPATH=$SYNAPSE_HOME/repository/conf:$JAVA_HOME/lib/tools.jar:$SYNAPSE_CLASSPATH:$CLASSPATH
# use proper bouncy castle version for the JDK
jdk_15=`$JAVA_HOME/bin/java -version 2>&1 | grep 1.5`
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org