Java - jndi ldap slow search



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















We are using javax.naming.ldap.LdapContext to connect and query an openLdap.



The problem is that we are getting com.sun.jndi.ldap.LdapSearchEnumeration as the results, and looping it is really slow, like 5 SearchResult per second.



I also tried with the apache ldap api and im getting the same times, unless i bring less atributes but its still slow. To get 180 results it takes 10 seconds.



Code example of jndi ldap:



 Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://aplivolatil....:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid=usuarioLector.....");
env.put(Context.SECURITY_CREDENTIALS, "9IVNOaQmEeE");
env.put(Context.BATCHSIZE, "1000");
env.put(Context.REFERRAL, "ignore");
LdapContext contexto;

try {
//contexto = new InitialLdapContext(env, null);
contexto = new InitialLdapContext(env, null);

SearchControls controlesBusqueda = new SearchControls();
String attrs = new String "cn";
controlesBusqueda.setReturningAttributes(attrs);
controlesBusqueda.setSearchScope(1);

NamingEnumeration<SearchResult> resultadosObjetos = contexto.search("cn=usuarios-......",
"(&(objectClass=inetOrgPerson))", controlesBusqueda);


while (resultadosObjetos.hasMore())
resultadosObjetos.next();



So, after investigation and several tests we found out that putting the jndi ldap environment property "batchsize" to 1000, the same delay goes to the search method instead of when looping the results. Which makes sense in a way that the api was going to ldap on every next() maybe. But why so much delay anyway ?



With rootDN goes super fast, 1 sec, could something be wrong with the user im using for searches ? which obviously is not the rootDN ?










share|improve this question






























    0















    We are using javax.naming.ldap.LdapContext to connect and query an openLdap.



    The problem is that we are getting com.sun.jndi.ldap.LdapSearchEnumeration as the results, and looping it is really slow, like 5 SearchResult per second.



    I also tried with the apache ldap api and im getting the same times, unless i bring less atributes but its still slow. To get 180 results it takes 10 seconds.



    Code example of jndi ldap:



     Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://aplivolatil....:389");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "uid=usuarioLector.....");
    env.put(Context.SECURITY_CREDENTIALS, "9IVNOaQmEeE");
    env.put(Context.BATCHSIZE, "1000");
    env.put(Context.REFERRAL, "ignore");
    LdapContext contexto;

    try {
    //contexto = new InitialLdapContext(env, null);
    contexto = new InitialLdapContext(env, null);

    SearchControls controlesBusqueda = new SearchControls();
    String attrs = new String "cn";
    controlesBusqueda.setReturningAttributes(attrs);
    controlesBusqueda.setSearchScope(1);

    NamingEnumeration<SearchResult> resultadosObjetos = contexto.search("cn=usuarios-......",
    "(&(objectClass=inetOrgPerson))", controlesBusqueda);


    while (resultadosObjetos.hasMore())
    resultadosObjetos.next();



    So, after investigation and several tests we found out that putting the jndi ldap environment property "batchsize" to 1000, the same delay goes to the search method instead of when looping the results. Which makes sense in a way that the api was going to ldap on every next() maybe. But why so much delay anyway ?



    With rootDN goes super fast, 1 sec, could something be wrong with the user im using for searches ? which obviously is not the rootDN ?










    share|improve this question


























      0












      0








      0


      1






      We are using javax.naming.ldap.LdapContext to connect and query an openLdap.



      The problem is that we are getting com.sun.jndi.ldap.LdapSearchEnumeration as the results, and looping it is really slow, like 5 SearchResult per second.



      I also tried with the apache ldap api and im getting the same times, unless i bring less atributes but its still slow. To get 180 results it takes 10 seconds.



      Code example of jndi ldap:



       Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
      env.put(Context.PROVIDER_URL, "ldap://aplivolatil....:389");
      env.put(Context.SECURITY_AUTHENTICATION, "simple");
      env.put(Context.SECURITY_PRINCIPAL, "uid=usuarioLector.....");
      env.put(Context.SECURITY_CREDENTIALS, "9IVNOaQmEeE");
      env.put(Context.BATCHSIZE, "1000");
      env.put(Context.REFERRAL, "ignore");
      LdapContext contexto;

      try {
      //contexto = new InitialLdapContext(env, null);
      contexto = new InitialLdapContext(env, null);

      SearchControls controlesBusqueda = new SearchControls();
      String attrs = new String "cn";
      controlesBusqueda.setReturningAttributes(attrs);
      controlesBusqueda.setSearchScope(1);

      NamingEnumeration<SearchResult> resultadosObjetos = contexto.search("cn=usuarios-......",
      "(&(objectClass=inetOrgPerson))", controlesBusqueda);


      while (resultadosObjetos.hasMore())
      resultadosObjetos.next();



      So, after investigation and several tests we found out that putting the jndi ldap environment property "batchsize" to 1000, the same delay goes to the search method instead of when looping the results. Which makes sense in a way that the api was going to ldap on every next() maybe. But why so much delay anyway ?



      With rootDN goes super fast, 1 sec, could something be wrong with the user im using for searches ? which obviously is not the rootDN ?










      share|improve this question
















      We are using javax.naming.ldap.LdapContext to connect and query an openLdap.



      The problem is that we are getting com.sun.jndi.ldap.LdapSearchEnumeration as the results, and looping it is really slow, like 5 SearchResult per second.



      I also tried with the apache ldap api and im getting the same times, unless i bring less atributes but its still slow. To get 180 results it takes 10 seconds.



      Code example of jndi ldap:



       Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
      env.put(Context.PROVIDER_URL, "ldap://aplivolatil....:389");
      env.put(Context.SECURITY_AUTHENTICATION, "simple");
      env.put(Context.SECURITY_PRINCIPAL, "uid=usuarioLector.....");
      env.put(Context.SECURITY_CREDENTIALS, "9IVNOaQmEeE");
      env.put(Context.BATCHSIZE, "1000");
      env.put(Context.REFERRAL, "ignore");
      LdapContext contexto;

      try {
      //contexto = new InitialLdapContext(env, null);
      contexto = new InitialLdapContext(env, null);

      SearchControls controlesBusqueda = new SearchControls();
      String attrs = new String "cn";
      controlesBusqueda.setReturningAttributes(attrs);
      controlesBusqueda.setSearchScope(1);

      NamingEnumeration<SearchResult> resultadosObjetos = contexto.search("cn=usuarios-......",
      "(&(objectClass=inetOrgPerson))", controlesBusqueda);


      while (resultadosObjetos.hasMore())
      resultadosObjetos.next();



      So, after investigation and several tests we found out that putting the jndi ldap environment property "batchsize" to 1000, the same delay goes to the search method instead of when looping the results. Which makes sense in a way that the api was going to ldap on every next() maybe. But why so much delay anyway ?



      With rootDN goes super fast, 1 sec, could something be wrong with the user im using for searches ? which obviously is not the rootDN ?







      java performance ldap jndi openldap






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 13:26







      Mateo

















      asked Nov 15 '18 at 15:58









      MateoMateo

      408




      408






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Apache has an LDAP API that they're working on. You can check it out here. Unfortunately, the documentation isn't very fleshed out at this point. A good number of pages on the User Guide are empty, but you can fill in the gaps with a little intuition and some help from the JavaDocs.



          Even with the lack of good tutorials, I've used this API before and had pretty good luck with it. I'd suggest giving it a try at the very least and see if things improve.






          share|improve this answer























          • i get the same time with apache ldap api, but what i noticed is that if i query less atributes the loop speeds up. As an example, 180 registers goes from 37 seconds to 10 seconds, that's better than getting all atributes. But i dont get it, why is so slow to loop the results anyway ? I confirmed its not going to ldap again, so am i missing something ? I will add the code example above.

            – Mateo
            Nov 16 '18 at 15:14






          • 1





            Since it's going slow for both implementations, it leads me to believe that it has something to do with the actual data itself. Unfortunately, I'm not entirely sure how you would go about making the loop faster. I would suggest putting in timers to see which call takes the most time. Is it cursor.next(), the Entry entry = cursor.get();, or is it actually the System.out.println() call? Set up a logger to see which one is at fault, and to see if it's always at fault, or just for certain values that it's looping through.

            – Francis Bartkowiak
            Nov 16 '18 at 18:21












          • Ive also tested the same query on phpldapadmin and it takes 1 sec, so i guess its Java related. And it wasnt the loop, cause i put the jndi ldap environment porperty batchsize as 1000, and now the search method has the same delay, but the loop is instantaneous. I will update the question.

            – Mateo
            Nov 20 '18 at 15:15












          • it was the user (security_principal) !! I dont know why, i ll keep investigating.

            – Mateo
            Nov 20 '18 at 17:10












          • The rootDN goes super fast, 1 sec. What could be the problem with the user im using for searches ? which obviously is not the rootDN.

            – Mateo
            Nov 21 '18 at 13:24











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323284%2fjava-jndi-ldap-slow-search%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Apache has an LDAP API that they're working on. You can check it out here. Unfortunately, the documentation isn't very fleshed out at this point. A good number of pages on the User Guide are empty, but you can fill in the gaps with a little intuition and some help from the JavaDocs.



          Even with the lack of good tutorials, I've used this API before and had pretty good luck with it. I'd suggest giving it a try at the very least and see if things improve.






          share|improve this answer























          • i get the same time with apache ldap api, but what i noticed is that if i query less atributes the loop speeds up. As an example, 180 registers goes from 37 seconds to 10 seconds, that's better than getting all atributes. But i dont get it, why is so slow to loop the results anyway ? I confirmed its not going to ldap again, so am i missing something ? I will add the code example above.

            – Mateo
            Nov 16 '18 at 15:14






          • 1





            Since it's going slow for both implementations, it leads me to believe that it has something to do with the actual data itself. Unfortunately, I'm not entirely sure how you would go about making the loop faster. I would suggest putting in timers to see which call takes the most time. Is it cursor.next(), the Entry entry = cursor.get();, or is it actually the System.out.println() call? Set up a logger to see which one is at fault, and to see if it's always at fault, or just for certain values that it's looping through.

            – Francis Bartkowiak
            Nov 16 '18 at 18:21












          • Ive also tested the same query on phpldapadmin and it takes 1 sec, so i guess its Java related. And it wasnt the loop, cause i put the jndi ldap environment porperty batchsize as 1000, and now the search method has the same delay, but the loop is instantaneous. I will update the question.

            – Mateo
            Nov 20 '18 at 15:15












          • it was the user (security_principal) !! I dont know why, i ll keep investigating.

            – Mateo
            Nov 20 '18 at 17:10












          • The rootDN goes super fast, 1 sec. What could be the problem with the user im using for searches ? which obviously is not the rootDN.

            – Mateo
            Nov 21 '18 at 13:24















          1














          Apache has an LDAP API that they're working on. You can check it out here. Unfortunately, the documentation isn't very fleshed out at this point. A good number of pages on the User Guide are empty, but you can fill in the gaps with a little intuition and some help from the JavaDocs.



          Even with the lack of good tutorials, I've used this API before and had pretty good luck with it. I'd suggest giving it a try at the very least and see if things improve.






          share|improve this answer























          • i get the same time with apache ldap api, but what i noticed is that if i query less atributes the loop speeds up. As an example, 180 registers goes from 37 seconds to 10 seconds, that's better than getting all atributes. But i dont get it, why is so slow to loop the results anyway ? I confirmed its not going to ldap again, so am i missing something ? I will add the code example above.

            – Mateo
            Nov 16 '18 at 15:14






          • 1





            Since it's going slow for both implementations, it leads me to believe that it has something to do with the actual data itself. Unfortunately, I'm not entirely sure how you would go about making the loop faster. I would suggest putting in timers to see which call takes the most time. Is it cursor.next(), the Entry entry = cursor.get();, or is it actually the System.out.println() call? Set up a logger to see which one is at fault, and to see if it's always at fault, or just for certain values that it's looping through.

            – Francis Bartkowiak
            Nov 16 '18 at 18:21












          • Ive also tested the same query on phpldapadmin and it takes 1 sec, so i guess its Java related. And it wasnt the loop, cause i put the jndi ldap environment porperty batchsize as 1000, and now the search method has the same delay, but the loop is instantaneous. I will update the question.

            – Mateo
            Nov 20 '18 at 15:15












          • it was the user (security_principal) !! I dont know why, i ll keep investigating.

            – Mateo
            Nov 20 '18 at 17:10












          • The rootDN goes super fast, 1 sec. What could be the problem with the user im using for searches ? which obviously is not the rootDN.

            – Mateo
            Nov 21 '18 at 13:24













          1












          1








          1







          Apache has an LDAP API that they're working on. You can check it out here. Unfortunately, the documentation isn't very fleshed out at this point. A good number of pages on the User Guide are empty, but you can fill in the gaps with a little intuition and some help from the JavaDocs.



          Even with the lack of good tutorials, I've used this API before and had pretty good luck with it. I'd suggest giving it a try at the very least and see if things improve.






          share|improve this answer













          Apache has an LDAP API that they're working on. You can check it out here. Unfortunately, the documentation isn't very fleshed out at this point. A good number of pages on the User Guide are empty, but you can fill in the gaps with a little intuition and some help from the JavaDocs.



          Even with the lack of good tutorials, I've used this API before and had pretty good luck with it. I'd suggest giving it a try at the very least and see if things improve.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 16:39









          Francis BartkowiakFrancis Bartkowiak

          8312619




          8312619












          • i get the same time with apache ldap api, but what i noticed is that if i query less atributes the loop speeds up. As an example, 180 registers goes from 37 seconds to 10 seconds, that's better than getting all atributes. But i dont get it, why is so slow to loop the results anyway ? I confirmed its not going to ldap again, so am i missing something ? I will add the code example above.

            – Mateo
            Nov 16 '18 at 15:14






          • 1





            Since it's going slow for both implementations, it leads me to believe that it has something to do with the actual data itself. Unfortunately, I'm not entirely sure how you would go about making the loop faster. I would suggest putting in timers to see which call takes the most time. Is it cursor.next(), the Entry entry = cursor.get();, or is it actually the System.out.println() call? Set up a logger to see which one is at fault, and to see if it's always at fault, or just for certain values that it's looping through.

            – Francis Bartkowiak
            Nov 16 '18 at 18:21












          • Ive also tested the same query on phpldapadmin and it takes 1 sec, so i guess its Java related. And it wasnt the loop, cause i put the jndi ldap environment porperty batchsize as 1000, and now the search method has the same delay, but the loop is instantaneous. I will update the question.

            – Mateo
            Nov 20 '18 at 15:15












          • it was the user (security_principal) !! I dont know why, i ll keep investigating.

            – Mateo
            Nov 20 '18 at 17:10












          • The rootDN goes super fast, 1 sec. What could be the problem with the user im using for searches ? which obviously is not the rootDN.

            – Mateo
            Nov 21 '18 at 13:24

















          • i get the same time with apache ldap api, but what i noticed is that if i query less atributes the loop speeds up. As an example, 180 registers goes from 37 seconds to 10 seconds, that's better than getting all atributes. But i dont get it, why is so slow to loop the results anyway ? I confirmed its not going to ldap again, so am i missing something ? I will add the code example above.

            – Mateo
            Nov 16 '18 at 15:14






          • 1





            Since it's going slow for both implementations, it leads me to believe that it has something to do with the actual data itself. Unfortunately, I'm not entirely sure how you would go about making the loop faster. I would suggest putting in timers to see which call takes the most time. Is it cursor.next(), the Entry entry = cursor.get();, or is it actually the System.out.println() call? Set up a logger to see which one is at fault, and to see if it's always at fault, or just for certain values that it's looping through.

            – Francis Bartkowiak
            Nov 16 '18 at 18:21












          • Ive also tested the same query on phpldapadmin and it takes 1 sec, so i guess its Java related. And it wasnt the loop, cause i put the jndi ldap environment porperty batchsize as 1000, and now the search method has the same delay, but the loop is instantaneous. I will update the question.

            – Mateo
            Nov 20 '18 at 15:15












          • it was the user (security_principal) !! I dont know why, i ll keep investigating.

            – Mateo
            Nov 20 '18 at 17:10












          • The rootDN goes super fast, 1 sec. What could be the problem with the user im using for searches ? which obviously is not the rootDN.

            – Mateo
            Nov 21 '18 at 13:24
















          i get the same time with apache ldap api, but what i noticed is that if i query less atributes the loop speeds up. As an example, 180 registers goes from 37 seconds to 10 seconds, that's better than getting all atributes. But i dont get it, why is so slow to loop the results anyway ? I confirmed its not going to ldap again, so am i missing something ? I will add the code example above.

          – Mateo
          Nov 16 '18 at 15:14





          i get the same time with apache ldap api, but what i noticed is that if i query less atributes the loop speeds up. As an example, 180 registers goes from 37 seconds to 10 seconds, that's better than getting all atributes. But i dont get it, why is so slow to loop the results anyway ? I confirmed its not going to ldap again, so am i missing something ? I will add the code example above.

          – Mateo
          Nov 16 '18 at 15:14




          1




          1





          Since it's going slow for both implementations, it leads me to believe that it has something to do with the actual data itself. Unfortunately, I'm not entirely sure how you would go about making the loop faster. I would suggest putting in timers to see which call takes the most time. Is it cursor.next(), the Entry entry = cursor.get();, or is it actually the System.out.println() call? Set up a logger to see which one is at fault, and to see if it's always at fault, or just for certain values that it's looping through.

          – Francis Bartkowiak
          Nov 16 '18 at 18:21






          Since it's going slow for both implementations, it leads me to believe that it has something to do with the actual data itself. Unfortunately, I'm not entirely sure how you would go about making the loop faster. I would suggest putting in timers to see which call takes the most time. Is it cursor.next(), the Entry entry = cursor.get();, or is it actually the System.out.println() call? Set up a logger to see which one is at fault, and to see if it's always at fault, or just for certain values that it's looping through.

          – Francis Bartkowiak
          Nov 16 '18 at 18:21














          Ive also tested the same query on phpldapadmin and it takes 1 sec, so i guess its Java related. And it wasnt the loop, cause i put the jndi ldap environment porperty batchsize as 1000, and now the search method has the same delay, but the loop is instantaneous. I will update the question.

          – Mateo
          Nov 20 '18 at 15:15






          Ive also tested the same query on phpldapadmin and it takes 1 sec, so i guess its Java related. And it wasnt the loop, cause i put the jndi ldap environment porperty batchsize as 1000, and now the search method has the same delay, but the loop is instantaneous. I will update the question.

          – Mateo
          Nov 20 '18 at 15:15














          it was the user (security_principal) !! I dont know why, i ll keep investigating.

          – Mateo
          Nov 20 '18 at 17:10






          it was the user (security_principal) !! I dont know why, i ll keep investigating.

          – Mateo
          Nov 20 '18 at 17:10














          The rootDN goes super fast, 1 sec. What could be the problem with the user im using for searches ? which obviously is not the rootDN.

          – Mateo
          Nov 21 '18 at 13:24





          The rootDN goes super fast, 1 sec. What could be the problem with the user im using for searches ? which obviously is not the rootDN.

          – Mateo
          Nov 21 '18 at 13:24



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323284%2fjava-jndi-ldap-slow-search%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo