From 64678e030f2ed2ee1bd0d8dfb9c7686eb4d79caa Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 14 May 2013 15:37:18 +0000
Subject: [PATCH] OPENDJ-808 (CR-1685) Implement a simple commons REST based HTTP connection handler
---
opends/resource/schema/02-config.ldif | 2
opends/src/server/org/opends/server/api/ConnectionHandler.java | 48 +++++++++++++--
opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java | 30 ---------
opends/src/server/org/opends/server/protocols/http/HTTPConnectionHandler.java | 12 +---
opends/src/admin/defn/org/opends/server/admin/std/HTTPConnectionHandlerConfiguration.xml | 34 +++++++++++
opends/src/admin/messages/HTTPConnectionHandlerCfgDefn.properties | 3 +
6 files changed, 83 insertions(+), 46 deletions(-)
diff --git a/opends/resource/schema/02-config.ldif b/opends/resource/schema/02-config.ldif
index a814b19..eb2a3a4 100644
--- a/opends/resource/schema/02-config.ldif
+++ b/opends/resource/schema/02-config.ldif
@@ -3915,7 +3915,7 @@
ds-cfg-use-tcp-no-delay $
ds-cfg-allow-tcp-reuse-address $
ds-cfg-max-request-size $
-# ds-cfg-num-request-handlers $ # TODO JNR TCPNIOTransport.setWorkerThreadPoolConfig()
+ ds-cfg-num-request-handlers $
ds-cfg-use-ssl $
ds-cfg-ssl-client-auth-policy $
ds-cfg-ssl-cert-nickname $
diff --git a/opends/src/admin/defn/org/opends/server/admin/std/HTTPConnectionHandlerConfiguration.xml b/opends/src/admin/defn/org/opends/server/admin/std/HTTPConnectionHandlerConfiguration.xml
index d8aff43..f23b1da 100644
--- a/opends/src/admin/defn/org/opends/server/admin/std/HTTPConnectionHandlerConfiguration.xml
+++ b/opends/src/admin/defn/org/opends/server/admin/std/HTTPConnectionHandlerConfiguration.xml
@@ -287,6 +287,40 @@
</ldap:attribute>
</adm:profile>
</adm:property>
+ <adm:property name="num-request-handlers" advanced="true">
+ <adm:synopsis>
+ Specifies the number of request handlers that are used to read
+ requests from clients.
+ </adm:synopsis>
+ <adm:description>
+ The
+ <adm:user-friendly-name />
+ uses one thread to accept new connections from clients, but uses
+ one or more additional threads to read requests from existing
+ client connections. This ensures that new requests are
+ read efficiently and that the connection handler itself does not
+ become a bottleneck when the server is under heavy load from many
+ clients at the same time.
+ </adm:description>
+ <adm:requires-admin-action>
+ <adm:component-restart />
+ </adm:requires-admin-action>
+ <adm:default-behavior>
+ <adm:alias>
+ <adm:synopsis>
+ Let the server decide.
+ </adm:synopsis>
+ </adm:alias>
+ </adm:default-behavior>
+ <adm:syntax>
+ <adm:integer lower-limit="1" />
+ </adm:syntax>
+ <adm:profile name="ldap">
+ <ldap:attribute>
+ <ldap:name>ds-cfg-num-request-handlers</ldap:name>
+ </ldap:attribute>
+ </adm:profile>
+ </adm:property>
<adm:property name="ssl-client-auth-policy">
<adm:synopsis>
Specifies the policy that the
diff --git a/opends/src/admin/messages/HTTPConnectionHandlerCfgDefn.properties b/opends/src/admin/messages/HTTPConnectionHandlerCfgDefn.properties
index 577968f..95acbfd 100644
--- a/opends/src/admin/messages/HTTPConnectionHandlerCfgDefn.properties
+++ b/opends/src/admin/messages/HTTPConnectionHandlerCfgDefn.properties
@@ -40,6 +40,9 @@
property.max-concurrent-ops-per-connection.default-behavior.alias.synopsis=Let the server decide.
property.max-request-size.synopsis=Specifies the size in bytes of the largest HTTP request message that will be allowed by the HTTP Connection Handler.
property.max-request-size.description=This can help prevent denial-of-service attacks by clients that indicate they send extremely large requests to the server causing it to attempt to allocate large amounts of memory.
+property.num-request-handlers.synopsis=Specifies the number of request handlers that are used to read requests from clients.
+property.num-request-handlers.description=The HTTP Connection Handler uses one thread to accept new connections from clients, but uses one or more additional threads to read requests from existing client connections. This ensures that new requests are read efficiently and that the connection handler itself does not become a bottleneck when the server is under heavy load from many clients at the same time.
+property.num-request-handlers.default-behavior.alias.synopsis=Let the server decide.
property.ssl-cert-nickname.synopsis=Specifies the nickname (also called the alias) of the certificate that the HTTP Connection Handler should use when performing SSL communication.
property.ssl-cert-nickname.description=This is only applicable when the HTTP Connection Handler is configured to use SSL.
property.ssl-cert-nickname.default-behavior.alias.synopsis=Let the server decide.
diff --git a/opends/src/server/org/opends/server/api/ConnectionHandler.java b/opends/src/server/org/opends/server/api/ConnectionHandler.java
index 375a53b..3c7b287 100644
--- a/opends/src/server/org/opends/server/api/ConnectionHandler.java
+++ b/opends/src/server/org/opends/server/api/ConnectionHandler.java
@@ -23,26 +23,25 @@
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
- * Portions copyright 2012 ForgeRock AS.
+ * Portions copyright 2012-2013 ForgeRock AS.
*/
package org.opends.server.api;
-import org.opends.messages.Message;
-
+import static org.opends.messages.ProtocolMessages.*;
+import static org.opends.server.loggers.ErrorLogger.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import org.opends.server.admin.std.server.*;
+import org.opends.messages.Message;
+import org.opends.server.admin.std.server.ConnectionHandlerCfg;
import org.opends.server.config.ConfigException;
import org.opends.server.monitors.ConnectionHandlerMonitor;
import org.opends.server.types.DN;
import org.opends.server.types.HostPort;
import org.opends.server.types.InitializationException;
-
-
/**
* This class defines the set of methods and structures that must be
* implemented by a Directory Server connection handler.
@@ -60,10 +59,10 @@
<T extends ConnectionHandlerCfg>
extends DirectoryThread
{
- // The monitor associated with this connection handler.
+ /** The monitor associated with this connection handler. */
private ConnectionHandlerMonitor monitor;
- // Is this handler the admin connection handler
+ /** Is this handler the admin connection handler. */
private boolean isAdminConnectionHandler = false;
@@ -296,6 +295,39 @@
/**
+ * Determine the number of request handlers.
+ *
+ * @param numRequestHandlers
+ * the number of request handlers from the configuration.
+ * @param friendlyName
+ * the friendly name of this connection handler
+ * @return the number of request handlers from the configuration determined
+ * from the configuration or from the number of available processors
+ * on the current machine
+ */
+ public int getNumRequestHandlers(Integer numRequestHandlers,
+ String friendlyName)
+ {
+ if (numRequestHandlers == null)
+ {
+ // Automatically choose based on the number of processors.
+ int cpus = Runtime.getRuntime().availableProcessors();
+ int value = Math.max(2, cpus / 2);
+
+ Message message =
+ INFO_ERGONOMIC_SIZING_OF_REQUEST_HANDLER_THREADS.get(friendlyName,
+ value);
+ logError(message);
+
+ return value;
+ }
+ else
+ {
+ return numRequestHandlers;
+ }
+ }
+
+ /**
* Retrieves a string representation of this connection handler.
*
* @return A string representation of this connection handler.
diff --git a/opends/src/server/org/opends/server/protocols/http/HTTPConnectionHandler.java b/opends/src/server/org/opends/server/protocols/http/HTTPConnectionHandler.java
index c44f70d..b6afd3b 100644
--- a/opends/src/server/org/opends/server/protocols/http/HTTPConnectionHandler.java
+++ b/opends/src/server/org/opends/server/protocols/http/HTTPConnectionHandler.java
@@ -523,9 +523,6 @@
throw new InitializationException(e.getMessageObject());
}
- // TODO JNR
- // handle ds-cfg-num-request-handlers??
-
// Create and register monitors.
statTracker = new HTTPStatistics(handlerName + " Statistics");
DirectoryServer.registerMonitorProvider(statTracker);
@@ -785,13 +782,10 @@
int bufferSize = (int) currentConfig.getBufferSize();
transport.setReadBufferSize(bufferSize);
transport.setWriteBufferSize(bufferSize);
- // TODO JNR
transport.setIOStrategy(SameThreadIOStrategy.getInstance());
- // ThreadPoolConfig workerPoolConfig =
- // ThreadPoolConfig.defaultConfig().copy();
- // workerPoolConfig.setCorePoolSize(currentConfig
- // .getNumRequestHandlers());
- // transport.setWorkerThreadPoolConfig(workerPoolConfig);
+ final int numRequestHandlers = getNumRequestHandlers(
+ currentConfig.getNumRequestHandlers(), friendlyName);
+ transport.setSelectorRunnersCount(numRequestHandlers);
transport.setServerConnectionBackLog(currentConfig.getAcceptBacklog());
if (sslContext != null)
diff --git a/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java b/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
index a98dad6..f58d39e 100644
--- a/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
+++ b/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
@@ -27,8 +27,6 @@
*/
package org.opends.server.protocols.ldap;
-
-
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
@@ -69,8 +67,6 @@
import org.opends.server.util.SelectableCertificateKeyManager;
import org.opends.server.util.StaticUtils;
-
-
/**
* This class defines a connection handler that will be used for communicating
* with clients over LDAP. It is actually implemented in two parts: as a
@@ -734,7 +730,8 @@
backlog = config.getAcceptBacklog();
listenAddresses = config.getListenAddress();
listenPort = config.getListenPort();
- numRequestHandlers = getNumRequestHandlers(config);
+ numRequestHandlers =
+ getNumRequestHandlers(config.getNumRequestHandlers(), friendlyName);
// Construct a unique name for this connection handler, and put
// together the set of listeners.
@@ -1543,27 +1540,4 @@
}
}
-
-
- // Determine the number of request handlers.
- private int getNumRequestHandlers(LDAPConnectionHandlerCfg configuration)
- {
- if (configuration.getNumRequestHandlers() == null)
- {
- // Automatically choose based on the number of processors.
- int cpus = Runtime.getRuntime().availableProcessors();
- int value = Math.max(2, cpus / 2);
-
- Message message = INFO_ERGONOMIC_SIZING_OF_REQUEST_HANDLER_THREADS.get(
- friendlyName, value);
- logError(message);
-
- return value;
- }
- else
- {
- return configuration.getNumRequestHandlers();
- }
- }
-
}
--
Gitblit v1.10.0