You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Ken Hu (Jira)" <ji...@apache.org> on 2022/12/19 19:56:00 UTC

[jira] [Commented] (TINKERPOP-2839) Make borrowing a connection from a pool async

    [ https://issues.apache.org/jira/browse/TINKERPOP-2839?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17649456#comment-17649456 ] 

Ken Hu commented on TINKERPOP-2839:
-----------------------------------

This behavior can be demonstrated if you run the following tests against the SimpleSocketServer.
{code:java}
@Test
public void shouldContinueRunningIfServerGoesDownTemporarily() throws InterruptedException, ExecutionException, TimeoutException {
    final Cluster cluster = Cluster.build("localhost").port(SimpleSocketServer.PORT)
            .minConnectionPoolSize(1)
            .maxConnectionPoolSize(2)
            .maxWaitForConnection(60000) // large value needed because server will go down in the middle of this test
            .connectionSetupTimeoutMillis(100)
            .minInProcessPerConnection(0)
            .maxInProcessPerConnection(2)
            .minSimultaneousUsagePerConnection(0)
            .maxSimultaneousUsagePerConnection(2)
            .reconnectInterval(10)
            .serializer(Serializers.GRAPHSON_V2D0)
            .create();

    final Client.ClusteredClient client = cluster.connect();

    ScheduledExecutorService scheduledPool = Executors.newScheduledThreadPool(1);
    scheduledPool.schedule(() -> {
        try {
            server.stopSync();
            server = new SimpleSocketServer();
            server.start(new TestWSGremlinInitializer());
        } catch (InterruptedException ignored) {
            // Ignored.
        }
    }, 500, TimeUnit.MILLISECONDS);

    List<CompletableFuture<ResultSet>> results = new ArrayList<CompletableFuture<ResultSet>>();
    for (int i = 0; i < 25; i++) {
        results.add(client.submitAsync("1"));
        Thread.sleep(100);
    }

    for (CompletableFuture<ResultSet> result : results) {
        try {
            assertNotNull(result.get(1000, TimeUnit.MILLISECONDS).one().getVertex());
        } catch (Exception e) {
            assertTrue(e instanceof IOException); // Make sure errors were due to server shutdown.
        }
    }

    // Final check to make sure that the client is working.
    assertNotNull(client.submit("1").one().getVertex());

    cluster.close();
}
{code}
The submitAsync() function call will block as a connection won't be made since the server goes down. This example demonstrates a different issue of having the main thread wait in cases where there is nothing to signal it.

> Make borrowing a connection from a pool async
> ---------------------------------------------
>
>                 Key: TINKERPOP-2839
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2839
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: driver
>    Affects Versions: 3.5.4
>            Reporter: Stephen Mallette
>            Priority: Minor
>
> TINKERPOP-2813 stopped fast {{NoHostAvaialbleException}} errors but the change made it more evident that {{submitAsync()}} was never as async as it should have been. Since {{ConnectionPool.borrowConnection()}} was synchronous you could still have a block, but it was then quickly hidden for future requests by the fast NHA that would follow a {{TimeoutException}} from that wait. It seems like borrowing a connection would have to be async if we wanted {{submitAsync()}} to be truly behave as its name implies.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)