LDAPの単純なパフォーマンステスト

背景

Javaのアクセスユーザーを使用して、第1のコンタクトLDAP、ジュニアインターンシップその夏は、ADサーバの属性と、基本的に従事する方法を忘れてしまいました。言語と私は、高いパフォーマンスを実現することができるかをテストしたいと思いADのユーザー獲得、例のLDAPサーバのセキュリティグループを書くために行きたかったです。しかし、誰良いLDAPライブラリが存在しない(良いかどうかは不明のみゴーのLDAP githubので見つかった、 -無力な言語の下に行くhttps://github.com/go-ldap/ldapは、後で再試行してくださいすることができます)。
LDAP操作を考慮すると、最も有名なのはOpenLDAPのでなければなりませんので、これを試してみたいと思います。

コードをダウンロードし、コンパイル

最新バージョンhttp://www.openldap.org/software/download/OpenLDAP/openldap-release/をダウンロードし、LIBのドキュメント:http://www.openldap.org/software/man.cgi?query=ldapインターネット検索は、再びそれをダウンロードし、2.4.15バージョンを使用するようにした後、私は間違っているの初めに、OpenLDAPの-2.4.46.tgz下にあった、次のバージョン2.4.9は、コンパイルエラーが直接、言いました。
設定なしSLAPDので、BDBはまた、行方不明のエラーを報告していないので、我々は--enable-SLDAP =何もスキップします。

./configure --enable-slapd=no
make depend
make
make install

インターネットは、ちょうど試してコンパイルし、それは本当にすることができ、コードを検索することができます。

gcc t1.c -L /usr/local/lib/ -lldap -llber

性能試験:テスト環境、古いコンピュータAMD A10 6700,12G DDR3、Hyper-Vはwindows2012をインストールし、ドメインコントローラを構成し、ドッキングウィンドウは、CentOSの、OpenLDAPのテストコードに基づいてコンパイルのCentOSを起動します。
次のようにテストコードがあります:

#include <stdio.h>
#include <ldap.h>
#include <sys/time.h>


void print_result(LDAP* ld, LDAPMessage *e)
{
    BerElement *ber;
    char *a;
    char **vals;
    int i;

    for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL; a = ldap_next_attribute( ld, e, ber ) )
    {
        if ((vals = ldap_get_values( ld, e, a)) != NULL )
        {
            for ( i = 0; vals[i] != NULL; i++ )
            {
                //printf( "%s: %s\n", a, vals[i] );

                if (0 == strcmp("memberOf", a))
                {
                    printf("get team:%s\n", vals[i]);
                }
            }
            //printf("print one val end\n");
            ldap_value_free( vals );
        }
        ldap_memfree( a );
    }

    if ( ber != NULL )
    {
        ber_free( ber, 0 );
    }

    //printf("print end\n");
}

void search_ext(LDAP *ld, char *finddn, char *filter)
{
    int rc;
    int msg;
    LDAPMessage *result, *e;
    int finish = 0;
    struct timeval tm = {0};
    tm.tv_sec = -1;

    rc = ldap_search_ext(ld, finddn, LDAP_SCOPE_SUBTREE, filter, NULL, 0, NULL, NULL, NULL, &tm, &msg);
    if (rc != LDAP_SUCCESS)
    {
        fprintf(stderr, "ldap_search_ext_s: rc: %d, %s\n", rc, ldap_err2string(rc));
        return( 1 );
    }

    //printf("ldap_search_ext success\n");

    int r = ldap_result(ld, msg, LDAP_MSG_ONE, NULL, &result);
    if (r > 0)
    {
        for (e = ldap_first_message(ld, result); e != NULL; e = ldap_next_message(ld, result))
        {
            print_result(ld, e);
        }
    }

    //printf("search_ext end\n");

    return;

}


int main()
{
    LDAP *ld;
    #define HOSTNAME "192.168.1.110"
    #define PORT_NUMBER 389
    #define FIND_DN "dc=test,dc=com"

    LDAPMessage *result, *e;
    BerElement *ber;
    char *a;
    char **vals;
    int i, rc;
    int i_version = 3;
    struct timeval tm = {0};
    tm.tv_sec = -1;

    ldap_set_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &i_version);
    ldap_set_option(NULL, LDAP_OPT_REFERRALS, LDAP_OPT_ON);

    time_t t1 = time(NULL);
    for (i = 0; i < 1000; i++)
    {
        if ( (ld = ldap_init( HOSTNAME, PORT_NUMBER )) == NULL )
        {  
            perror( "ldap_init" );
            return( 1 );
        }
        //printf( "ldap_init success\n" );

        rc = ldap_simple_bind_s( ld, "cn=administrator,cn=Users,dc=test,dc=com", "Yanhong001");
        if ( rc != LDAP_SUCCESS )
        {
            fprintf(stderr, "ldap_simple_bind_s: rc: %d, %s\n", rc, ldap_err2string(rc));
            return( 1 );
        }

        // printf( "ldap_simple_bind_s success\n" );

        search_ext(ld, "dc=test, dc=com", "(&(objectclass=person)(sAMAccountName=user001))");

        //printf("searchexe end:%d\n", i);

        ldap_unbind_ext(ld, NULL, NULL);
    }
    time_t t2 = time(NULL);

    printf("time:%d\n", t2-t1);

    return 0;
}

テスト結果:プリント、認証および検索実行時間1000年6秒せずに、印刷8秒では、認証だけならば、5秒を検索しません。説明最適化の余地がここにあります。これは2回目の検索を実行するときldap_resultは、キャプチャを通して見て、一定の時間で立ち往生され、一度だけ認定し、検索をリサイクルし、ADサーバは、各要求の後、すぐに応答するが、クライアントは常にzeroWindowとを送信しますキープアライブメッセージは、それらがOpenLDAPの待機ではなく、サーバーの応答にやっていると推定されます。

おすすめ

転載: www.cnblogs.com/luckpiky/p/11441919.html