directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159173 - in directory/sandbox/trunk/asn1-new-codec/src/perfs: ./ org/ org/apache/ org/apache/ans1/ org/apache/ans1/ber/ org/apache/ans1/ber/LdapDecoderPerf.java
Date Sun, 27 Mar 2005 18:43:13 GMT
Author: elecharny
Date: Sun Mar 27 10:43:12 2005
New Revision: 159173

URL: http://svn.apache.org/viewcvs?view=rev&rev=159173
Log:
A first working version of the new ASN.1 LDAP decoder.

Added:
    directory/sandbox/trunk/asn1-new-codec/src/perfs/
    directory/sandbox/trunk/asn1-new-codec/src/perfs/org/
    directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/
    directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/
    directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/
    directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java

Added: directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java?view=auto&rev=159173
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java
Sun Mar 27 10:43:12 2005
@@ -0,0 +1,183 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ans1.ber;
+
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.codec.DecoderException;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.codec.LdapMessageGrammar;
+import org.apache.asn1.ldap.pojo.BindRequestPOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.asn1.ldap.pojo.SimpleAuthenticationPOJO;
+import org.apache.asn1.util.pools.PoolEnum;
+import org.apache.asn1.util.pools.PoolException;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * A performance test.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ */
+public class LdapDecoderPerf extends Thread
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** Logger */
+    protected static Logger log = Logger.getLogger( LdapDecoderPerf.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * A performance test...
+     */
+    public void run()
+    {
+        Asn1Decoder ldapDecoder = new Asn1Decoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x35 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x33, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x60, 0x2E, 		//        CHOICE { ..., bindRequest BindRequest, ...
+                        			// BindRequest ::= APPLICATION[0] SEQUENCE {
+				0x02, 0x01, 0x03, 	//        version INTEGER (1..127),
+				0x04, 0x1F, 		//        name LDAPDN,
+				'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+                'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+				( byte ) 0x80, 0x08, //        authentication AuthenticationChoice
+                                     // AuthenticationChoice ::= CHOICE { simple [0] OCTET
STRING, ...
+				'p', 'a', 's', 's', 'w', 'o', 'r', 'd'
+            } );
+
+        stream.flip();
+
+        try
+        {
+
+            long t0 = System.currentTimeMillis();
+
+            for ( int i = 0; i < 1000000; i++ )
+            {
+                log.debug( "---------------------> " + i );
+
+                // Allocate a BindRequest Container
+                IAsn1Container ldapMessageContainer = null;
+
+                try
+                {
+                    ldapMessageContainer = ( IAsn1Container ) ldapDecoder.allocate(
+                            PoolEnum.LDAP_MESSAGE_CONTAINER_POOL );
+                }
+                catch ( PoolException pe )
+                {
+                    log.error( "Cannot allocat a LdapMessageContainer : " + pe.getMessage()
);
+
+                    return;
+                }
+
+                ldapMessageContainer.setGrammar( LdapMessageGrammar.getInstance() );
+                ldapMessageContainer.setPoolManager( ldapDecoder.getPoolManager() );
+
+                ldapDecoder.decode( stream, ldapMessageContainer );
+
+                // Free the BindRequest Container. It will be put back in the IPool
+                // after being reset.
+                ldapMessageContainer.free();
+                stream.flip();
+            }
+
+            long t1 = System.currentTimeMillis();
+
+            System.out.println( "Delta = " + ( t1 - t0 ) );
+        }
+        catch ( DecoderException de )
+        {
+            log.error( de.getMessage() );
+            de.printStackTrace();
+        }
+
+        try
+        {
+
+            IAsn1Container ldapMessageContainer = ( IAsn1Container ) ldapDecoder.allocate(
+                    PoolEnum.LDAP_MESSAGE_CONTAINER_POOL );
+
+            ldapDecoder.decode( stream, ldapMessageContainer );
+
+            // Free the BindRequest Container. It will be put back in the IPool
+            // after being reset.
+            //bindRequestContainer.free();
+            LdapMessagePOJO message = ( ( LdapMessageContainer ) ldapMessageContainer )
+                .getLdapMessage();
+            BindRequestPOJO br      = ( BindRequestPOJO ) ( message.getProtocolOp() );
+
+            System.out.println( "BindRequest decoded :" );
+            System.out.println( "	MessageId 	= " + message.getMessageId() );
+            System.out.println( "	Version 	= " + br.getVersion() );
+            System.out.println( "	Name	 	= " + br.getName() );
+            System.out.println( "	Authentication	= " +
+                ( ( br.getAuthentication() instanceof SimpleAuthenticationPOJO ) ? "Simple"
: "sasl" ) );
+            System.out.println( "	simple		= " +
+                ( ( SimpleAuthenticationPOJO ) br.getAuthentication() ).getSimple() );
+
+            ldapMessageContainer.free();
+        }
+        catch ( DecoderException de )
+        {
+            log.error( de.getMessage() );
+            de.printStackTrace();
+        }
+        catch ( PoolException pe )
+        {
+            log.error( "Cannot allocat a BindRequestContainer : " + pe.getMessage() );
+
+            return;
+        }
+    }
+
+    /**
+     * Main
+     *
+     * @param args DOCUMENT ME!
+     */
+    public static void main( String[] args )
+    {
+
+        LdapDecoderPerf ldpt1 = new LdapDecoderPerf();
+        LdapDecoderPerf ldpt2 = new LdapDecoderPerf();
+        LdapDecoderPerf ldpt3 = new LdapDecoderPerf();
+        LdapDecoderPerf ldpt4 = new LdapDecoderPerf();
+
+        ldpt1.start();
+        ldpt2.start();
+        ldpt3.start();
+        ldpt4.start();
+    }
+}



Mime
View raw message