0

I try to get one username item on LDAP server, but my client code will spent 0.6s, it is too slow, I don't know why. but the 'ldapsearch' and 'LDAP Admin' is too fast, so I think the problem is not from the LDAP server, does anyone can give me some clue, why my code is slow? Thanks!:)

int main(int argc, char *argv[])
{
        LDAP  *ld;
        char  *dn;
        int   version, rc;

        const char *root_dn = "cn=ldapadm,dc=extreme3,dc=com";
        char *root_pass = "Password123!";

        printf("Connecting %s in port %d...\n\n", HOSTNAME, PORTNUMBER);

        rc = ldap_initialize(&ld, HOSTNAME);
        if ( rc != LDAP_SUCCESS )
        {
            printf("Error !");
        }

        version = LDAP_VERSION3;
        ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version);

        printf("Bind!\n");
        rc = ldap_simple_bind_s(ld, root_dn, root_pass);
        if (rc != LDAP_SUCCESS) {
            fprintf(stderr, "Error: %s\n", ldap_err2string(rc));
            return (1);
        }

        LDAPMessage* res = nullptr;
        ldap_search_s(ld, "dc=extreme3,dc=com", LDAP_SCOPE_SUBTREE, "(uid=ncvm9141196u1432)", 0, 0, &res);    //slow at here

        int count = ldap_count_entries(ld, res);
        printf("Result: %d S:\n", count);

        ldap_unbind(ld);
        return(0);
  }

////////////////////////////////

c4dev@sles15-guol13-dev-00:/c4_working/code> time ./prog
Connecting ldap://10.109.14.51 in port 389...

Bind!
Result: 1

real 0m0.626s
user 0m0.027s
sys 0m0.000s

Dangerman
  • 43
  • 7
  • Does this answer your question? https://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1 – 463035818_is_not_an_ai Apr 13 '20 at 07:44
  • *"...but the 'ldapsearch' and 'LDAP Admin' is too fast" - So.. you're saying using CLI utilities and/or GUI shows now performance issues, but your code isn't as fortunate? – WhozCraig Apr 13 '20 at 07:44
  • @WhozCraig I mean that I use 'CLI utilities' on my client PC to query item on LDAP server, it is very fast, but I run my code on my PC, it is very slow, I don't know why my code(LDAP api) is slow. – Dangerman Apr 13 '20 at 07:50
  • it isnt your code that is slow. Out of the 0.6 seconds almost nothing is taken by your code (see link above) – 463035818_is_not_an_ai Apr 13 '20 at 07:56
  • @idclev463035818, I use 'ldap_search_s' to get user name item from LDAP server. the slow point is here. – Dangerman Apr 13 '20 at 08:18

0 Answers0