Le 27/01/15 06:11, Harris, Christopher P a écrit :
> Hi,
>
> I'm running into TimeOut issues when implementing a multi-threaded approach 
> to read all of LDAP/AD into memory, starting with the CEO and trickling down. 

Can you tell us how you do that ? Ie, are you using a plain new
connection for each thread you spawn ?

In any case, the TimeOut is the default LDapConnection timeout (30
seconds) :

    /** The timeout used for response we are waiting for */
    private long timeout = LdapConnectionConfig.DEFAULT_TIMEOUT;

    /** The default timeout for operation : 30 seconds */
    public static final long DEFAULT_TIMEOUT = 30000L;

That means the server is *not* responding for more than 30 seconds.

>  I haven't been using the LdapConnectionPool, so I thought that I'd give that 
> a try to see if it solves my TimeOut issues.  I'm setting the timeout for my 
> cursor and connection to 300,000 milliseconds, however the timeout 
> consistently occurs around 30 seconds I've noticed.

You have to set the LdapConnectionConfig timeout for all the created
connections to use it. there is a setTimeout() method for that which has
been added in 1.0.0-M28.
>
> Anyway, I read the docs concerning implementing an LdapConnectionPool, but 
> the example doesn't show you how to use the connection pool.
>
> Does the following method use the LdapConnectionPool the correct way?
>
> public Person searchLdapUsingConnectionPool() {
>              SearchCursor cursor = new SearchCursorImpl(null, 30000, 
> TimeUnit.SECONDS);
>              LdapConnectionPool pool = null;
>              LdapConnection connection = null;
>              Person p = null;
>              try {
>                     LdapConnectionConfig config = new LdapConnectionConfig();
>                     config.setLdapHost( host );
>                     config.setLdapPort( port );
>                     config.setName( dn );
>                     config.setCredentials( pwd );
>                     DefaultPoolableLdapConnectionFactory factory = new 
> DefaultPoolableLdapConnectionFactory( config );
>                     pool = new LdapConnectionPool( factory );
>                     pool.setTestOnBorrow( true );
>                     connection = pool.getConnection();

It's all good. You can now change the config timeout :
config.setTimeOut( whatever fits you );
>
>                     Entry entry = null;
>
>
>             SearchRequest sr = new SearchRequestImpl();
>             sr.setBase(new Dn(searchBase));
>             StringBuilder sb = new StringBuilder(ceoQuery);
>             sr.setFilter(sb.toString());
>             sr.setScope( SearchScope.SUBTREE );
>             cursor = connection.search(sr);
>             Response response;
>
>             while (cursor.next() && cursor.isEntry()) {
>                 response = cursor.get();
>                 System.out.println(((SearchResultEntry)response).getEntry());
>                 entry = cursor.getEntry();
>                 EntryMapper<Person> em = Person.getEntryMapper();
>                    p = em.map(entry);
>             }
>         } catch (LdapException ex) {
>             Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, 
> null, ex);
>         } catch (CursorException ex) {
>             Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, 
> null, ex);
>         } finally {
>             cursor.close();
>             try {
>                 pool.releaseConnection(connection);
>             } catch (LdapException ex) {
>             Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, 
> null, ex);
>                     }
>         }
>
>         return p;
>        }
>
> It seems like I just need to grab a connection via pool.getConnection(), but 
> I don't know for sure if I'm using it the recommended way.  

It is the right way.


Side note : you may face various problems when pulling everything from
an AD server. Typically, the AD config might not let you pull more than
1000 entries, as there is a hard limit you need to change on AD if you
want to get more entries.

Otherwise, the approach - ie, using multiple threads - might seems good,
but the benefit is limited. Pulling entries from the server is fast, you
should be able to get tens of thousands per second with one single
thread. I'm not sure how AD support concurrent searches anyway. Last,
not least, it's likely that AD does not allow more than a certain number
of concurrent threads to run, which might lead to contention at some point.

Hope it helps.

Emmanuel

Reply via email to