Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool implementation for one-shot queries does not use all available resources #742

Closed
tsegismont opened this issue Aug 19, 2020 · 0 comments · Fixed by #743
Closed

Pool implementation for one-shot queries does not use all available resources #742

tsegismont opened this issue Aug 19, 2020 · 0 comments · Fixed by #743
Labels
Milestone

Comments

@tsegismont
Copy link
Contributor

When executing one-shot queries, the pool implementation will often schedule the SQL commands on the few available connections instead of creating more if maximum size has not been reached.

Consider the following test:

  @Test
  public void testUseAvailableResources(TestContext ctx) {
    int poolSize = 10;
    Async async = ctx.async();
    PgPool pool = PgPool.pool(options, new PoolOptions().setMaxSize(poolSize));
    AtomicReference<PgConnection> ctrlConnRef = new AtomicReference<>();
    PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(ctrlConn -> {
      ctrlConnRef.set(ctrlConn);
      for (int i = 0; i < poolSize; i++) {
        vertx.setTimer(10 * (i + 1), l -> {
          pool.query("select pg_sleep(5)").execute(ar -> {});
        });
      }
      vertx.setTimer(10 * (poolSize + 1), event -> {
        ctrlConn.query("select count(*) as cnt from pg_stat_activity where application_name like '%vertx%'").execute(ctx.asyncAssertSuccess(rows -> {
          Integer count = rows.iterator().next().getInteger("cnt");
          ctx.assertEquals(poolSize + 1, count);
          async.complete();
        }));
      });
    }));
    try {
      async.await();
    } finally {
      PgConnection ctrlConn = ctrlConnRef.get();
      if (ctrlConn != null) {
        ctrlConn.close();
      }
      pool.close();
    }
  }

It fails like this:

java.lang.AssertionError: Not equals : 11 != 2

This test targets Postgres but the problem is in PoolBase implementation so I believe it affects all SQL clients.

@tsegismont tsegismont added the bug label Aug 19, 2020
tsegismont added a commit to tsegismont/vertx-sql-client that referenced this issue Aug 20, 2020
@tsegismont tsegismont added this to the 3.9.3 milestone Aug 20, 2020
tsegismont added a commit to tsegismont/vertx-sql-client that referenced this issue Aug 20, 2020
@vietj vietj closed this as completed Aug 21, 2020
DavideD pushed a commit to DavideD/vertx-sql-client that referenced this issue Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants