[Mulgara-svn] r1521 - in trunk: conf src/jar/server/java/org/mulgara/server
alexhall at mulgara.org
alexhall at mulgara.org
Tue Feb 17 22:27:04 UTC 2009
Author: alexhall
Date: 2009-02-17 14:27:03 -0800 (Tue, 17 Feb 2009)
New Revision: 1521
Modified:
trunk/conf/mulgara-embedded.dtd
trunk/conf/mulgara-embedded.xsd
trunk/src/jar/server/java/org/mulgara/server/HttpServices.java
Log:
Add a configuration parameter to enable the setting of the maximum thread pool size in the Jetty connector. This is different from the existing parameter that controls the number of acceptors. Acceptors simply accept an incoming connection and dispatch it to a worker thread. Since each acceptor is allocated a thread in the thread pool, increasing the number of acceptors while keeping the maximum number of threads constant may negatively impact performance by decreasing the number of worker threads available to process requests.
Modified: trunk/conf/mulgara-embedded.dtd
===================================================================
--- trunk/conf/mulgara-embedded.dtd 2009-02-17 21:17:28 UTC (rev 1520)
+++ trunk/conf/mulgara-embedded.dtd 2009-02-17 22:27:03 UTC (rev 1521)
@@ -9,12 +9,13 @@
<!ELEMENT Jetty (Connector, PublicConnector)>
- <!ELEMENT Connector (Disabled?, Host?, Port, Acceptors?, MaxIdleTimeMs?, LowResourceMaxIdleTimeMs?)>
- <!ELEMENT PublicConnector (Disabled?, Host?, Port, Acceptors?, MaxIdleTimeMs?, LowResourceMaxIdleTimeMs?)>
+ <!ELEMENT Connector (Disabled?, Host?, Port, Acceptors?, MaxThreads?, MaxIdleTimeMs?, LowResourceMaxIdleTimeMs?)>
+ <!ELEMENT PublicConnector (Disabled?, Host?, Port, Acceptors?, MaxThreads?, MaxIdleTimeMs?, LowResourceMaxIdleTimeMs?)>
<!ELEMENT Host (#PCDATA)>
<!ELEMENT Port (#PCDATA)>
<!ELEMENT Acceptors (#PCDATA)>
+ <!ELEMENT MaxThreads (#PCDATA)>
<!ELEMENT MaxIdleTimeMs (#PCDATA)>
<!ELEMENT LowResourceMaxIdleTimeMs (#PCDATA)>
Modified: trunk/conf/mulgara-embedded.xsd
===================================================================
--- trunk/conf/mulgara-embedded.xsd 2009-02-17 21:17:28 UTC (rev 1520)
+++ trunk/conf/mulgara-embedded.xsd 2009-02-17 22:27:03 UTC (rev 1521)
@@ -25,6 +25,7 @@
<xs:element ref="Host" minOccurs="0"/>
<xs:element ref="Port"/>
<xs:element ref="Acceptors" minOccurs="0"/>
+ <xs:element ref="MaxThreads" minOccurs="0"/>
<xs:element ref="MaxIdleTimeMs" minOccurs="0"/>
<xs:element ref="LowResourceMaxIdleTimeMs" minOccurs="0"/>
</xs:sequence>
@@ -37,6 +38,7 @@
<xs:element ref="Host" minOccurs="0"/>
<xs:element ref="Port"/>
<xs:element ref="Acceptors" minOccurs="0"/>
+ <xs:element ref="MaxThreads" minOccurs="0"/>
<xs:element ref="MaxIdleTimeMs" minOccurs="0"/>
<xs:element ref="LowResourceMaxIdleTimeMs" minOccurs="0"/>
</xs:sequence>
@@ -45,6 +47,7 @@
<xs:element name="LowResourceMaxIdleTimeMs" type="xs:int"/>
<xs:element name="MaxIdleTimeMs" type="xs:int"/>
<xs:element name="Acceptors" type="xs:int"/>
+ <xs:element name="MaxThreads" type="xs:int"/>
<xs:element name="DefaultGraph" type="xs:string"/>
<xs:element name="PersistencePath" type="xs:string"/>
<xs:element name="Port" type="xs:int"/>
Modified: trunk/src/jar/server/java/org/mulgara/server/HttpServices.java
===================================================================
--- trunk/src/jar/server/java/org/mulgara/server/HttpServices.java 2009-02-17 21:17:28 UTC (rev 1520)
+++ trunk/src/jar/server/java/org/mulgara/server/HttpServices.java 2009-02-17 22:27:03 UTC (rev 1521)
@@ -39,6 +39,7 @@
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.webapp.WebAppClassLoader;
import org.mortbay.jetty.webapp.WebAppContext;
+import org.mortbay.thread.QueuedThreadPool;
import org.mortbay.util.MultiException;
import org.mulgara.config.Connector;
import org.mulgara.config.MulgaraConfig;
@@ -99,9 +100,6 @@
/** Key to the bound server model uri in the attribute map of the servlet context. */
public final static String SERVER_MODEL_URI_KEY = "serverModelURI";
- /** The maximum number of acceptors that Jetty can handle. It locks above this number. */
- private static final int WEIRD_JETTY_THREAD_LIMIT = 24;
-
/** The HTTP server instance. */
private final Server httpServer;
@@ -315,15 +313,27 @@
if (logger.isDebugEnabled()) logger.debug("Servlet container listening on all host interfaces");
}
+ // Each connector will get its own thread pool, so that they may be configured separately.
+ // If a connector does not have its own thread pool, it inherits one from the server that it might
+ // share with other connectors.
+ QueuedThreadPool threadPool = new QueuedThreadPool();
+ if (jettyConfig.hasMaxThreads()) {
+ threadPool.setMaxThreads(jettyConfig.getMaxThreads());
+ }
+ connector.setThreadPool(threadPool);
if (jettyConfig.hasPort()) connector.setPort(jettyConfig.getPort());
if (jettyConfig.hasMaxIdleTimeMs()) connector.setMaxIdleTime(jettyConfig.getMaxIdleTimeMs());
if (jettyConfig.hasLowResourceMaxIdleTimeMs()) connector.setLowResourceMaxIdleTime(jettyConfig.getLowResourceMaxIdleTimeMs());
if (jettyConfig.hasAcceptors()) {
int acceptors = jettyConfig.getAcceptors();
- if (acceptors > WEIRD_JETTY_THREAD_LIMIT) {
- logger.warn("Acceptor threads set beyond HTTP Server limits. Reducing from" + acceptors + " to " + WEIRD_JETTY_THREAD_LIMIT);
- acceptors = WEIRD_JETTY_THREAD_LIMIT;
+ // Acceptors are part of the thread pool, but they delegate handling of servlet
+ // requests to another thread in the pool. Therefore, the number of acceptors
+ // must be strictly less than the maximum number of threads in the pool.
+ int acceptorLimit = threadPool.getMaxThreads() - 1;
+ if (acceptors > acceptorLimit) {
+ logger.warn("Acceptor threads set beyond HTTP Server limits. Reducing from" + acceptors + " to " + acceptorLimit);
+ acceptors = acceptorLimit;
}
connector.setAcceptors(acceptors);
}
@@ -460,6 +470,7 @@
String host = null;
Integer port = null;
Integer acceptors = null;
+ Integer maxThreads = null;
Integer maxIdleTimeMs = null;
Integer lowResourceMaxIdleTimeMs = null;
@@ -474,6 +485,7 @@
host = c.getHost();
if (c.hasPort()) port = c.getPort();
if (c.hasAcceptors()) acceptors = c.getAcceptors();
+ if (c.hasMaxThreads()) maxThreads = c.getMaxThreads();
if (c.hasMaxIdleTimeMs()) maxIdleTimeMs = c.getMaxIdleTimeMs();
if (c.hasLowResourceMaxIdleTimeMs()) lowResourceMaxIdleTimeMs = c.getLowResourceMaxIdleTimeMs();
}
@@ -489,6 +501,7 @@
host = c.getHost();
if (c.hasPort()) port = c.getPort();
if (c.hasAcceptors()) acceptors = c.getAcceptors();
+ if (c.hasMaxThreads()) maxThreads = c.getMaxThreads();
if (c.hasMaxIdleTimeMs()) maxIdleTimeMs = c.getMaxIdleTimeMs();
if (c.hasLowResourceMaxIdleTimeMs()) lowResourceMaxIdleTimeMs = c.getLowResourceMaxIdleTimeMs();
}
@@ -517,6 +530,11 @@
public int getAcceptors() {
return acceptors;
}
+
+ /** @return the maximum number of threads for the thread pool. */
+ public int getMaxThreads() {
+ return maxThreads;
+ }
/** @return the maxIdleTimeMs */
public int getMaxIdleTimeMs() {
@@ -543,6 +561,11 @@
return acceptors != null;
}
+ /** @return <code>true</code> if the MaxThreads value was provided. */
+ public boolean hasMaxThreads() {
+ return maxThreads != null;
+ }
+
/** @return <code>true</code> if the MaxIdelTimeMs value was provided. */
public boolean hasMaxIdleTimeMs() {
return maxIdleTimeMs != null;
More information about the Mulgara-svn
mailing list