You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/07/16 06:29:52 UTC

svn commit: r422371 - /directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java

Author: akarasulu
Date: Sat Jul 15 21:29:52 2006
New Revision: 422371

URL: http://svn.apache.org/viewvc?rev=422371&view=rev
Log:
Added feature to be able to control connection sharing.

Modified:
    directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java

Modified: directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java?rev=422371&r1=422370&r2=422371&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java (original)
+++ directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java Sat Jul 15 21:29:52 2006
@@ -26,6 +26,7 @@
 
 import com.sun.slamd.job.JobClass;
 import com.sun.slamd.job.UnableToRunException;
+import com.sun.slamd.parameter.BooleanParameter;
 import com.sun.slamd.parameter.IntegerParameter;
 import com.sun.slamd.parameter.InvalidValueException;
 import com.sun.slamd.parameter.Parameter;
@@ -40,8 +41,13 @@
 
 
 /**
+ * A simple bind benchmark.  Here the same bindDn and password is 
+ * used to bind to the directory.  The connection to the directory is
+ * by default shared across iterations of a thread but this can be 
+ * changed.  This is not a real world experiment but a way for us to
+ * stress test the server, profile it, optimize it and regression test
+ * our results under stress for more reliable feedback.
  * 
- *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
@@ -75,6 +81,11 @@
     // Extracted paramter values for the whole Job
     // -----------------------------------------------------------------------
 
+    // The connection is estabilished anew every time for each bind request
+    // if this option is not selected instead of reusing the existing connection
+    // for each iteration.  The default is to share the connection.
+    static boolean shareConnections;
+    
     // Indicates whether bind failures because of invalid credentials will be
     // ignored (so we can optimize for authn failures as well).
     static boolean ignoreInvalidCredentials;
@@ -108,6 +119,13 @@
     // Paramters definitions
     // -----------------------------------------------------------------------
 
+    // The parameter controlling where or not connections are reused
+    BooleanParameter shareConnectionsParameter = new BooleanParameter( "shareConnectionsParameter",
+        "Share Connections", 
+        "Specifies whether or not the connection to the LDAP server is shared or " +
+        "re-estabilished every time for each iteration.  If true the iteration creates" +
+        "and destroys a new connection before issueing a bind request.", true );
+    
     // The parameter that indicates the delay that should be used between each
     // authentication attempt.
     IntegerParameter delayParameter = new IntegerParameter( "delay", "Time Between Authentications (ms)",
@@ -205,7 +223,7 @@
         Parameter[] parameterArray = new Parameter[]
             { placeholder, hostParameter, portParameter, bindDNParameter, bindPWParameter, placeholder,
                 warmUpParameter, timeLimitParameter, delayParameter, placeholder,
-                iterationsParameter };
+                iterationsParameter, shareConnectionsParameter };
 
         return new ParameterList( parameterArray );
     }
@@ -363,6 +381,18 @@
      */
     public void initializeClient( String clientID, ParameterList parameters ) throws UnableToRunException
     {
+        // Get the shareConnections boolean parameter
+        shareConnectionsParameter = parameters.getBooleanParameter( shareConnectionsParameter.getName() );
+        if ( hostParameter == null )
+        {
+            shareConnections = true; // the default
+        }
+        else
+        {
+            shareConnections = shareConnectionsParameter.getBooleanValue();
+        }
+        
+        
         // Get the directory server address
         hostParameter = parameters.getStringParameter( hostParameter.getName() );
         if ( hostParameter == null )
@@ -439,22 +469,25 @@
     public void initializeThread( String clientID, String threadID, int collectionInterval, ParameterList parameters )
         throws UnableToRunException
     {
-        bindConnection = new LDAPConnection();
-
-        try
-        {
-            bindConnection.connect( 3, directoryHost, directoryPort, "", "" );
-        }
-        catch ( Exception e )
+        if ( shareConnections )
         {
-            throw new UnableToRunException( "Unable to establish the connections " + "to the directory server:  " + e,
-                e );
+            bindConnection = new LDAPConnection();
+    
+            try
+            {
+                bindConnection.connect( 3, directoryHost, directoryPort, "", "" );
+            }
+            catch ( Exception e )
+            {
+                throw new UnableToRunException( "Unable to establish the connections " + "to the directory server:  " + e,
+                    e );
+            }
+    
+            // Initialize the constraints.
+            bindConstraints = bindConnection.getConstraints();
+            bindConstraints.setTimeLimit( 1000 * timeLimit );
         }
-
-        // Initialize the constraints.
-        bindConstraints = bindConnection.getConstraints();
-        bindConstraints.setTimeLimit( 1000 * timeLimit );
-
+    
         // Create the stat trackers.
         attemptCounter = new IncrementalTracker( clientID, threadID, STAT_TRACKER_AUTHENTICATION_ATTEMPTS,
             collectionInterval );
@@ -540,6 +573,25 @@
                 }
             }
 
+            if ( ! shareConnections )
+            {
+                bindConnection = new LDAPConnection();
+                
+                try
+                {
+                    bindConnection.connect( 3, directoryHost, directoryPort, "", "" );
+                }
+                catch ( Exception e )
+                {
+                    throw new IllegalStateException( "Unable to establish the connections " 
+                        + "to the directory server:  " + e, e );
+                }
+        
+                // Initialize the constraints.
+                bindConstraints = bindConnection.getConstraints();
+                bindConstraints.setTimeLimit( 1000 * timeLimit );
+            }
+
             if ( collectingStats )
             {
                 attemptCounter.increment();
@@ -574,6 +626,24 @@
                     .append( " - " ).append( le.getLDAPErrorMessage() );
                 writeVerbose( buf.toString() );
             }
+            finally
+            {
+                if ( ! shareConnections )
+                {
+                    if ( bindConnection != null )
+                    {
+                        try
+                        {
+                            bindConnection.disconnect();
+                        }
+                        catch ( Exception e )
+                        {
+                        }
+            
+                        bindConnection = null;
+                    }
+                }
+            }
         }
 
         attemptCounter.stopTracker();
@@ -589,17 +659,20 @@
      */
     public void destroy()
     {
-        if ( bindConnection != null )
+        if ( shareConnections )
         {
-            try
-            {
-                bindConnection.disconnect();
-            }
-            catch ( Exception e )
+            if ( bindConnection != null )
             {
+                try
+                {
+                    bindConnection.disconnect();
+                }
+                catch ( Exception e )
+                {
+                }
+    
+                bindConnection = null;
             }
-
-            bindConnection = null;
         }
     }
 }