Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1Z8g-0005cW-98 for psycopg@arkaria.postgresql.org; Mon, 18 Jan 2021 18:20:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l1Z8f-0003iK-7f for psycopg@arkaria.postgresql.org; Mon, 18 Jan 2021 18:20:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1Z8f-0003iD-1N for psycopg@lists.postgresql.org; Mon, 18 Jan 2021 18:20:29 +0000 Received: from mail-vs1-xe29.google.com ([2607:f8b0:4864:20::e29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l1Z8c-0004jT-5E for psycopg@postgresql.org; Mon, 18 Jan 2021 18:20:28 +0000 Received: by mail-vs1-xe29.google.com with SMTP id w187so8699838vsw.5 for ; Mon, 18 Jan 2021 10:20:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JzwGZu/j0pPbVwaw+jW2fq/XJk5cwuoLH+WONN2HI9s=; b=abzbQLFSJ1hxCMLv7EnZVWii0FWaatO8gUILdo9EXlGGrPkBZvzcKsrgKcpJhwbCPW 5PaVRgBpOm2TzJThPClCACGi30HSf/2DbPtMSu3aeR2JeOfN6jfSnGuB09TdPtzSOFDB 1c56RnnzZ7S7OS3Wt16gU6B1V1vrt2oXHq80pmC7WGJkQ8DoZcYOKBRi5fuzA8Fk2vHH KlZxelPdG2NVzfra8LYfDYm6npte2xUlbW9OIUksrcGmM8XGxqAQXeX7UZKpsL+OOJh0 sr9VSU8DNP5kGEQ326Qxw9uH6DyCEAdBdxELtIvcaUmR2ValiDXCestbk06sys+zJfwa TADQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JzwGZu/j0pPbVwaw+jW2fq/XJk5cwuoLH+WONN2HI9s=; b=f+Fj8HmulCoWx0bPo3LrSb+gIuiHnOM+qiofA9CGVT8RdH+GmMWYoqM9RYsVHbmbvi M7/FIGjg4/UxBiNF3go+At7raVORUF1grXIoUom9/kKUCtwqLePA9aNjSbTKrsTAhOxb BTcbGFURlZUjqwbCNUFEw2uarHw/95CC2k2PoHyzEnYaN7NeFmfPdhVMEQ9n0Nx3SLQb Yo50/LzH+dMHAVCYyHhRTRG7V738NXEiuaYzu4swG1mXmbvvDhiE0QWTtl54yx/PJ8zZ NSyko7mYWnhXhH0q1o4CQjZxfvkqGvc4ujqLPP/vLVLCT/tdneZ6owLza93WOkHX4ty9 shCA== X-Gm-Message-State: AOAM533O0t2XUvj4a9PE8DsFNWuhYOKLSahiGPK5XoLB/jYri69gdWWy ewKG4CS3IbQ8r2nxQmuBkNBz4P/hJyJZe99BPjU= X-Google-Smtp-Source: ABdhPJyXQ+rDYMeQcUcxKCCCowrRnI4O9iumuPJEI6IFF2W/4jYEAVIIGHse/06oKw2zjD+I7jx2u1XGzgH3Tc2Ehrg= X-Received: by 2002:a67:c918:: with SMTP id w24mr648183vsk.4.1610994023667; Mon, 18 Jan 2021 10:20:23 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Vladimir Ryabtsev Date: Mon, 18 Jan 2021 10:20:12 -0800 Message-ID: Subject: Re: Designing a better connection pool for psycopg3 To: Daniele Varrazzo Cc: psycopg@postgresql.org Content-Type: multipart/alternative; boundary="000000000000841a5d05b930c60b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000841a5d05b930c60b Content-Type: text/plain; charset="UTF-8" > Connection configuration In my opinion it is not only static vs dynamic, I have a feeling that subclassing gives more freedom for improper implementation (resulting in problems). Also it depends on internal API (not necessarily public), which puts more obligations on the maintainer to keep it compatible with old releases. In this case I like the configuring approach better (and it does not exclude subclassing as well). > Exclusive connections? The feature itself seems useful, but what are the benefits of getting it from the pool (e.g. checking state, reconnection, configuration) as opposed to creating one manually? Is such a connection counted in regard to 'minconn', 'maxconn'? > What to do in case of connection failure? > A first step towards a sane behaviour could be to die early, on startup, if the connection is not working when the first pool population is done Agree. BTW, at which moment will the driver be trying to connect? At pool initialization or on first "getconn()"? > What if the database is missing in action during the program lifetime? Following connection attempts may be repeated, with an exponential backoff, until dying after a few minutes of fruitless attempts Yes, I would prefer exponential backoff, with a timeout prior to "panic" callback. Preferably, both configurable. > Connections usage pattern I don't see cases where an application should bother about it, choose whatever is better for your implementation. And yes, stack looks reasonable. > 'minconn', Proposed default: 4 Many services and applications do not really need many connections but would like to benefit from automatic reconnections. So the default is questionable, as many people will leave it unchanged. > "get_info()" One thing that comes into my head every time I use connection pools is how many are really needed for my application. Usually it is adjusted experimentally or using some performance tests. Can you collect and provide some stats to get more insights on that? I see you want to expose some in "get_info()", which exactly? E.g. number of times the max limit was hit, current number of connections acquired? > 'max_lifetime_sec' Why is it necessary at all? Does a connection get rotten with time? As I understand, you are planning to check a connection state in background. As long as it is OK, what is the need to replace it? > num_workers, default: 3 Assuming every worker does the same job, is there really the amount of work for three workers? "get_maintenance_task()" This API seems to be too advanced, in what cases you see a sane use case for it? Thank you, Vladimir On Mon, 18 Jan 2021 at 04:04, Daniele Varrazzo wrote: > Hello, > > I've been gathering a few ideas about the connection pool I would like > to provide with psycopg3. I would be happy if you would like to take a > look and give some feedback. > > https://www.psycopg.org/articles/2021/01/17/pool-design/ > > Thank you very much, > > -- Daniele > > > --000000000000841a5d05b930c60b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> Connection configuration
In my opinion it is not = only static vs dynamic,
I have a feeling that subclassing gives mor= e freedom for improper
implementation (resulting in problems). Al= so it depends on internal
API (not necessarily=C2=A0public), whic= h puts more obligations on the
maintainer to keep it compatible w= ith old releases. In this case
I like the configuring approach be= tter
(and it does not exclude subclassing as well).
> Exclusive connections?
The feature itself seems useful, but= what are the benefits of getting it
from the pool (e.g. checking= state, reconnection, configuration)
as opposed to creating one m= anually?
Is such a connection=C2=A0counted in regard to 'minc= onn', 'maxconn'?

> What to do in case of= connection failure?
> A first step towards a sane behaviour could be= to die early, on startup, if the connection is not working when the first = pool population is done
Agree.
BTW, at which moment will the d= river be trying to connect? At pool
initialization or on first &q= uot;getconn()"?

> What if the database is missing in = action during the program lifetime? Following connection attempts may be re= peated, with an exponential backoff, until dying after a few minutes of fru= itless attempts
Yes, I would prefer exponential backoff, with a timeout = prior to "panic" callback.
Preferably, both configurable.
<= br>> Connections usage pattern
I don't see cases where an applica= tion should bother about it,
choose whatever is better for your implemen= tation. And=C2=A0yes, stack
looks reasonable.

> 'mi= nconn', Proposed default: 4
Many services and applications do not re= ally need many connections
but would like to benefit from automatic reco= nnections. So the default
is questionable, as many people will leave it = unchanged.

> "get_info()"
One thing that comes into = my head every time I use connection pools
is how many are really needed = for my application. Usually it is adjusted
experimentally or using some = performance tests. Can you collect and
provide some stats to get more in= sights on that? I see you want to
expose some in "get_info()",= which exactly? E.g. number of times
the max limit was hit, current numb= er of connections acquired?

> 'max_lifetime_sec'Why is it necessary at all? Does a connection get rotten with time?
As= I understand, you are planning to check a connection state in
backgroun= d. As long as it is OK, what is the need to replace it?

> num_wor= kers, default: 3
Assuming every worker does the same job, is there reall= y the amount
of work for three workers?

"get_maintenance_tas= k()"
This API seems to be too advanced, in what cases you see a san= e use case for it?

Thank you,
Vladim= ir


On Mon, 18 Jan 2021 at 04:04, Daniele Varrazzo <<= a href=3D"mailto:daniele.varrazzo@gmail.com">daniele.varrazzo@gmail.com= > wrote:
Hell= o,

I've been gathering a few ideas about the connection pool I would like<= br> to provide with psycopg3. I would be happy if you would like to take a
look and give some feedback.

https://www.psycopg.org/articles/2021/01/17/= pool-design/

Thank you very much,

-- Daniele


--000000000000841a5d05b930c60b--