mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
14.37.2013 64678e030f2ed2ee1bd0d8dfb9c7686eb4d79caa
OPENDJ-808 (CR-1685) Implement a simple commons REST based HTTP connection handler



Added support for ds-cfg-num-request-handlers in the HTTPConnectionHandler configuration to bring it at par with the LDAPConnectionHandler configuration.



02-config.ldif, HTTPConnectionHandlerConfiguration.xml, HTTPConnectionHandlerCfgDefn.properties:
Added ds-cfg-num-request-handlers.

HTTPConnectionHandler.java:
Set the SelectorRunnersCount in grizzly based on the numRequestHandlers property.

LDAPConnectionHandler.java, ConnectionHandler.java:
Moved getNumRequestHandlers() from LDAPConnectionHandler to ConnectionHandler.
6 files modified
129 ■■■■■ changed files
opends/resource/schema/02-config.ldif 2 ●●● patch | view | raw | blame | history
opends/src/admin/defn/org/opends/server/admin/std/HTTPConnectionHandlerConfiguration.xml 34 ●●●●● patch | view | raw | blame | history
opends/src/admin/messages/HTTPConnectionHandlerCfgDefn.properties 3 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/api/ConnectionHandler.java 48 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/http/HTTPConnectionHandler.java 12 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java 30 ●●●●● patch | view | raw | blame | history
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 $
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
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.
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.
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)
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();
    }
  }
}