From 187d6e3758dfa7e87c4f9fe170b67759b28ced81 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Mon, 06 Jun 2011 13:38:18 +0000
Subject: [PATCH] Fix OPENDJ-186: Change default values for LDAP request handlers, JE backend cache size, and replication purge delay

---
 opendj-sdk/opends/src/admin/messages/LDAPConnectionHandlerCfgDefn.properties                        |    1 
 opendj-sdk/opends/src/server/org/opends/server/admin/AdministrationConnector.java                   |    3 +
 opendj-sdk/opends/resource/config/config.ldif                                                       |    4 -
 opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LDAPConnectionHandlerConfiguration.xml |    9 +++-
 opendj-sdk/opends/src/messages/messages/protocol.properties                                         |    3 +
 opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java            |   57 ++++++++++++++++++++++------
 opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml     |    3 +
 opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LocalDBBackendConfiguration.xml        |    4 +-
 8 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/opendj-sdk/opends/resource/config/config.ldif b/opendj-sdk/opends/resource/config/config.ldif
index 4410343..0e0e25b 100644
--- a/opendj-sdk/opends/resource/config/config.ldif
+++ b/opendj-sdk/opends/resource/config/config.ldif
@@ -187,7 +187,7 @@
 ds-cfg-preload-time-limit: 0 seconds
 ds-cfg-entries-compressed: false
 ds-cfg-compact-encoding: true
-ds-cfg-db-cache-percent: 10
+ds-cfg-db-cache-percent: 50
 ds-cfg-db-cache-size: 0 megabytes
 ds-cfg-db-txn-no-sync: false
 ds-cfg-db-txn-write-no-sync: true
@@ -444,7 +444,6 @@
 ds-cfg-max-request-size: 5 megabytes
 ds-cfg-buffer-size: 4096 bytes
 ds-cfg-max-blocked-write-time-limit: 2 minutes
-ds-cfg-num-request-handlers: 2
 ds-cfg-allow-start-tls: false
 ds-cfg-use-ssl: false
 ds-cfg-ssl-client-auth-policy: optional
@@ -469,7 +468,6 @@
 ds-cfg-max-request-size: 5 megabytes
 ds-cfg-buffer-size: 4096 bytes
 ds-cfg-max-blocked-write-time-limit: 2 minutes
-ds-cfg-num-request-handlers: 2
 ds-cfg-allow-start-tls: false
 ds-cfg-use-ssl: true
 ds-cfg-ssl-client-auth-policy: optional
diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LDAPConnectionHandlerConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LDAPConnectionHandlerConfiguration.xml
index c4e1ac1..04e2dad 100644
--- a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LDAPConnectionHandlerConfiguration.xml
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LDAPConnectionHandlerConfiguration.xml
@@ -24,6 +24,7 @@
   !
   !
   !      Copyright 2007-2009 Sun Microsystems, Inc.
+  !      Portions copyright 2011 ForgeRock AS
   ! -->
 <adm:managed-object name="ldap-connection-handler"
   plural-name="ldap-connection-handlers"
@@ -480,9 +481,11 @@
       <adm:component-restart />
     </adm:requires-admin-action>
     <adm:default-behavior>
-      <adm:defined>
-        <adm:value>2</adm:value>
-      </adm:defined>
+      <adm:alias>
+        <adm:synopsis>
+          Let the server decide.
+        </adm:synopsis>
+      </adm:alias>
     </adm:default-behavior>
     <adm:syntax>
       <adm:integer lower-limit="1" />
diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LocalDBBackendConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LocalDBBackendConfiguration.xml
index fcf5bd4..3c04749 100644
--- a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LocalDBBackendConfiguration.xml
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/LocalDBBackendConfiguration.xml
@@ -24,7 +24,7 @@
   !
   !
   !      Copyright 2007-2010 Sun Microsystems, Inc.
-  !      Portions Copyright 2010 ForgeRock AS.
+  !      Portions Copyright 2010-2011 ForgeRock AS.
   ! -->
 <adm:managed-object name="local-db-backend"
   plural-name="local-db-backends" package="org.opends.server.admin.std"
@@ -408,7 +408,7 @@
     </adm:description>
     <adm:default-behavior>
       <adm:defined>
-        <adm:value>10</adm:value>
+        <adm:value>50</adm:value>
       </adm:defined>
     </adm:default-behavior>
     <adm:syntax>
diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml
index 5b3fcd4..173baec 100644
--- a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/ReplicationServerConfiguration.xml
@@ -24,6 +24,7 @@
   !
   !
   !      Copyright 2007-2010 Sun Microsystems, Inc.
+  !      Portions copyright 2011 ForgeRock AS
   ! -->
 <adm:managed-object name="replication-server"
   plural-name="replication-servers"
@@ -162,7 +163,7 @@
     </adm:synopsis>
     <adm:default-behavior>
       <adm:defined>
-        <adm:value>86400s</adm:value>
+        <adm:value>3 days</adm:value>
       </adm:defined>
     </adm:default-behavior>
     <adm:syntax>
diff --git a/opendj-sdk/opends/src/admin/messages/LDAPConnectionHandlerCfgDefn.properties b/opendj-sdk/opends/src/admin/messages/LDAPConnectionHandlerCfgDefn.properties
index 5b0d4db..ef73700 100644
--- a/opendj-sdk/opends/src/admin/messages/LDAPConnectionHandlerCfgDefn.properties
+++ b/opendj-sdk/opends/src/admin/messages/LDAPConnectionHandlerCfgDefn.properties
@@ -40,6 +40,7 @@
 property.max-request-size.description=This property is analogous to the maxBERSize configuration attribute of the Sun Java System Directory Server. 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 LDAP 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.send-rejection-notice.synopsis=Indicates whether the LDAP Connection Handler should send a notice of disconnection extended response message to the client if a new connection is rejected for some reason.
 property.send-rejection-notice.description=The extended response message may provide an explanation indicating the reason that the connection was rejected.
 property.ssl-cert-nickname.synopsis=Specifies the nickname (also called the alias) of the certificate that the LDAP Connection Handler should use when performing SSL communication.
diff --git a/opendj-sdk/opends/src/messages/messages/protocol.properties b/opendj-sdk/opends/src/messages/messages/protocol.properties
index 28363e7..4808a1d 100644
--- a/opendj-sdk/opends/src/messages/messages/protocol.properties
+++ b/opendj-sdk/opends/src/messages/messages/protocol.properties
@@ -1426,4 +1426,5 @@
  decode the control value:  %s
 SEVERE_ERR_UNEXPECTED_CONNECTION_CLOSURE_1511=The connection to the Directory \
 Server was closed while waiting for a response
-
+INFO_ERGONOMIC_SIZING_OF_REQUEST_HANDLER_THREADS_1512=Connection handler '%s' \
+ does not specify the number of request handler threads: defaulting to %d threads
diff --git a/opendj-sdk/opends/src/server/org/opends/server/admin/AdministrationConnector.java b/opendj-sdk/opends/src/server/org/opends/server/admin/AdministrationConnector.java
index 087d15c..1f332c8 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/admin/AdministrationConnector.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/admin/AdministrationConnector.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
+ *      Portions copyright 2011 ForgeRock AS
  */
 package org.opends.server.admin;
 
@@ -431,7 +432,7 @@
     /**
      * {@inheritDoc}
      */
-    public int getNumRequestHandlers()
+    public Integer getNumRequestHandlers()
     {
       return ADMIN_NUM_REQUEST_HANDLERS;
     }
diff --git a/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java b/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
index 76936e7..ffd5370 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
+ *      Portions copyright 2011 ForgeRock AS
  */
 package org.opends.server.protocols.ldap;
 import static org.opends.messages.ProtocolMessages.*;
@@ -239,26 +240,28 @@
    * be initialized before it may be used.
    */
   public LDAPConnectionHandler() {
-   this(new WorkQueueStrategy(), DEFAULT_FRIENDLY_NAME);
+   this(new WorkQueueStrategy(), null); // Use name from configuration.
   }
 
 
+
   /**
    * Creates a new instance of this LDAP connection handler, using a queueing
    * strategy. It must be initialized before it may be used.
-   * @param strategy Request handling strategy.
-   * @param friendlyName Friendly name to use in this connector.
-   *        If null, the default one is used.
+   *
+   * @param strategy
+   *          Request handling strategy.
+   * @param friendlyName
+   *          The name of of this connection handler, or {@code null} if the
+   *          name should be taken from the configuration.
    */
-  public LDAPConnectionHandler(QueueingStrategy strategy, String friendlyName) {
-    super(DEFAULT_FRIENDLY_NAME + " Thread");
+  public LDAPConnectionHandler(QueueingStrategy strategy,
+      String friendlyName)
+  {
+    super(friendlyName != null ? friendlyName : DEFAULT_FRIENDLY_NAME
+        + " Thread");
 
-    if (friendlyName == null) {
-      this.friendlyName = DEFAULT_FRIENDLY_NAME;
-    } else {
-      this.friendlyName = friendlyName;
-    }
-
+    this.friendlyName = friendlyName;
     this.queueingStrategy = strategy;
 
     // No real implementation is required. Do all the work in the
@@ -637,6 +640,12 @@
   public void initializeConnectionHandler(LDAPConnectionHandlerCfg config)
          throws ConfigException, InitializationException
   {
+    if (friendlyName == null)
+    {
+      friendlyName = config.dn().getRDN().getAttributeValue(0)
+          .toString();
+    }
+
     // Open the selector.
     try {
       selector = Selector.open();
@@ -670,7 +679,7 @@
     backlog = config.getAcceptBacklog();
     listenAddresses = config.getListenAddress();
     listenPort = config.getListenPort();
-    numRequestHandlers = config.getNumRequestHandlers();
+    numRequestHandlers = getNumRequestHandlers(config);
 
     // Construct a unique name for this connection handler, and put
     // together the
@@ -1348,4 +1357,26 @@
     }
   }
 
+
+  // 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