Menu

LDAPConnectionPool connection timeout

Patrick
2013-08-12
2013-08-13
  • Patrick

    Patrick - 2013-08-12

    Hello,

    I have an LDAPConnectionPool that uses server round-robin so I use one of the constructors that has the ServerSet parameter. When setting it up this way, is there anywhere that I can specify the connection timeout for each connection? I can’t seem to find any way to do it with this constructor and the timeout for a server that is down seems to be very long.

    Thanks,
    Patrick

     
  • Neil Wilson

    Neil Wilson - 2013-08-12

    The maximum length of time to spend trying to establish a connection can be specified via the LDAPConnectionOptions.setConnectTimeoutMillis method, and you can provide an LDAPConnectionOptions object in the RoundRobinServerSet constructor. By default, the connect timeout is 60000 milliseconds, or one minute.

    Also note that when creating a connection pool, you can specify how many threads should be used when establishing the initial set of connections. This can help further reduce the length of time required to create a connection pool because it allows you to create multiple connections at the same time.

    Finally, if you're not already aware of it, the LDAP SDK also provides a FastestConnectServerSet implementation. When it is used to create a connection, it will try to connect in parallel to all of the servers that have been configured, and will use the first one to be established. This might be a good alternative to setting a very small connect timeout in some environments, particularly when you might need to connect to a remote system or over some other kind of slow network.

    Neil

     
  • Patrick

    Patrick - 2013-08-12

    Aha, I missed looking in the RoundRobinServerSet. Perfect.

    Also good info about the FastestConnectServerSet but I do want to keep all available ones in rotation.

    Thanks for the quick reply, Neil. Great SDK!

     
  • Patrick

    Patrick - 2013-08-13

    Follow-up question. I am testing some failure scenarios and am getting results that I don't quite understand. In this case there are 5 servers in the set and only 1 is available. Even with the connection timeout set to 1 second and multiple connector threads, the pool in this example takes about two minutes to figure out which servers are available and start up. Here is the startup code:

            String[] ips = portalConfigurationService.getLdapIps();         
            int[] ports = new int[ips.length];
            Arrays.fill(ports, portalConfigurationService.getLdapPort());
            LDAPConnectionOptions options = new LDAPConnectionOptions();
            options.setConnectTimeoutMillis(1000);
            options.setAllowConcurrentSocketFactoryUse(true);
            ServerSet serverSet = new RoundRobinServerSet(ips, ports, options);
            SimpleBindRequest bindRequest = new SimpleBindRequest(portalConfigurationService.getLdapConnectionUsername(), portalConfigurationService.getLdapPassword());
            ldapConnectionPool = new LDAPConnectionPool(serverSet, bindRequest, portalConfigurationService.getLdapMinPoolSize(), portalConfigurationService.getLdapMaxPoolSize(),
                    ips.length*2, null, false);
    

    Anything jump out as obviously wrong here? What I basically want is a pool that gives me all reachable servers and throws out the ones that are not reachable (only trying for 1-2 seconds to connect to each).

    Thanks.

     
  • Neil Wilson

    Neil Wilson - 2013-08-13

    I don't immediately see a problem with your code, and I'm not sure why it's taking a couple of minutes to establish the connections.

    It would be very useful if you could use a tool like jstack in order to capture a stack trace of all active threads sometime during this two-minute period so that it's possible to see where things are getting held up. It would also be helpful to know how you're simulating the "unreachable" condition (e.g., is the system up but the directory server not running, is the system completely off or disconnected from the network, etc.).

    Thanks.

    Neil

     
  • Patrick

    Patrick - 2013-08-13

    In this case the 'unreachable' servers do not respond to a connect request (totally unreachable via network) so a timeout is inevitable.

    I played around with it a bit more and the problem seems to stem from setting 'initialConnections' to a higher value. If I use 10, for example, then the pool wants 10 connections so it is iterating through the list continually until it builds up 10. Since 4 out of 5 time out, that means 10 rotations each with 4 timeouts = 40 * TIMEOUT_VAL delay.

    This is not a huge problem though, I can just set initialConnections to 1 I think.

     

    Last edit: Patrick 2013-08-14

Log in to post a comment.