Announcement Announcement Module
Collapse
No announcement yet.
Spring LDAP Limit returned results Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring LDAP Limit returned results

    Hi,

    I search via Spring LDAP in a DN which would return a whole bunch of results (SizeLimitExceededException is thrown) but I would need only one of those (it is a pool of generated ID's).

    This works perfectly with a CollectingNameClassPairCallbackHandler, but it is lacking performance. A search request for one specific DN usually takes <100ms, the getID takes about 2,5s .That is I guess because of the fact that there are so many of them until the SizeLimitExceededException occurs.

    Is it possible to limit the result to get just a single entry from that DN and therefore improve the performance or is this a general LDAP issue?

    Thanks in advance
    Marcus

    ------
    Here's my search
    Code:
    SearchControls searchControls = new SearchControls();
    searchControls.setCountLimit(1);
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    searchControls.setReturningAttributes(new String[] { "id", "new_id" } );
    
    CollectingNameClassPairCallbackHandler handler = 
    			new AttributesMapperCallbackHandler(new IDAttributeMapper());
    
    try {
      ldapTemplate.search(dn, "id=*", searchControls, handler);
    } catch (Exception e) {
    	if(e instanceof SizeLimitExceededException) {
    		// safely ignore. Spring LDAP handles this exception different to SUNs implementation.
    	}
    	else {
    		throw e;
    	}
    
    }
    
    return handler.getList().get(0);
    Last edited by mmueller; Jan 11th, 2008, 05:46 AM.

  • #2
    Interesting. Testing your code, I seem to always get a search time of around 30 ms, regardless of how many entries I have in the tree. I used the following code for catching the search limit exception:

    Code:
    try {
       tested.search(BASE_STRING, FILTER_STRING, searchControls, handler);
    }
    catch (LimitExceededException e) {
    }
    Could you post the rest of your code?

    How many ids do you have in the pool normally?

    Comment


    • #3
      Investigating further, I found a way that seems to be cheaper still than using the CollectingNameClassPairCallbackHandler and setting the search limit to one, namely by implementing NameClassPairCallbackHandler directly and simply throw an exception when you have the first value. This approach consistently takes around 10 ms compared to the other that takes 30-40 ms. The reason is probably the List handling overhead in CollectingNameClassPairCallbackHandler.

      Code:
      public class LdapTemplateLimitSearchITest extends AbstractLdapTemplateIntegrationTest {
         private String singleValue = null;
         private LdapTemplate tested;
         ... 
         public void testLimitedSearchUsingNameClassPairCallbackHandlerTakesReasonableTime() {
            NameClassPairCallbackHandler handler = new NameClassPairCallbackHandler() {
               public void handleNameClassPair(NameClassPair nameClassPair) {
                  SearchResult searchResult = (SearchResult) nameClassPair;
                  try {
                     singleValue = (String) searchResult.getAttributes().get("description").get();
                     throw new FirstValueAlreadySetException();
                  }
                  catch (NamingException e) {
                     throw LdapUtils.convertLdapException(e);
                  }
               }
            };
            SearchControls searchControls = new SearchControls();
            searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            searchControls.setReturningAttributes(new String[] { "description" });
      
            try {
               tested.search(BASE_STRING, FILTER_STRING, searchControls, handler);
            }
            catch (FirstValueAlreadySetException e) {
            }
      
            assertNotNull(singleValue);
            System.out.println("Got id: " + singleValue);
         }
      
         private static class FirstValueAlreadySetException extends RuntimeException {
         }
      }
      Last edited by ulsa; Jan 12th, 2008, 12:48 PM. Reason: Fixed class name typos

      Comment

      Working...
      X