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 1lbhCp-0004PC-DS for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Apr 2021 10:14:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lbhCn-0007BU-1a for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Apr 2021 10:14:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbhCm-0007BN-H9 for pgsql-hackers@lists.postgresql.org; Wed, 28 Apr 2021 10:14:04 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lbhCj-0005JU-1Z for pgsql-hackers@postgresql.org; Wed, 28 Apr 2021 10:14:03 +0000 Received: by mail-wr1-x435.google.com with SMTP id t18so4827963wry.1 for ; Wed, 28 Apr 2021 03:14:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:in-reply-to:references:comments:mime-version :content-id:content-transfer-encoding:date:message-id; bh=MZplqpTdgEaRMGyDkQ4iisb2G+sfosHC/lj9XR35d5Q=; b=bVsYxK/3ROnTX8IbdtQ2fdi5HwXxJOzO5eftrE+dPOG1w4k/h1R/ioJjFu5HGMa+06 GxfbkB75QtGEV+E5yHlJT/ocddT+q07267viv9RonZaxieBznS93Pnkx55lHiTpYQoYU rwK/f2nQ1VVhwsnMMGNvxztVccTiJmR3zcfhiD2KbfAiQMBrAKroLRN0oZ6mx0Ct9Y5m NGV6HmmEZZzHBaP6V9v1bs4eP1YIHQs1flzk/rQVS4HQ8bi3sv4eAiad7LoEYa9lF3hy Q/KnsMn6DPHH14MnfgD+xgomnHqLJiJ0AIG0BRnmpGxJLCwR1RQ2xSBIVcZuaU+MbIBF Wr/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :comments:mime-version:content-id:content-transfer-encoding:date :message-id; bh=MZplqpTdgEaRMGyDkQ4iisb2G+sfosHC/lj9XR35d5Q=; b=cXIsc2xHqGbYM/S0lBXg8OVQgXWu15NWndsrXFUBAhDuVVDFgd3s2CtqXESc0b1YTt XrtolsjnQ61yRKPfNY8bi4wbVqeQrkShWg5Qdao32UiHB7w8ZXw0rGlDCMZ5wqgBYE/Q OjVBpwdtAszftctoUxua5kpSjqYG7Aa15t9Qm6Ov2GoyCbKnSat03IQIlvCnP78lTNC1 uLwxb2Xe74nnNqTuUOpmiPMzxYPL5z3bSwyyDMqMQ0MFfy9wyBsCD/pTPvhf/Xk7oXds lYuOOaUg9q2nIbRN/vJHtm1XM7YzWfFIix0fV/UjJCg2+XmeLIca2ByutnDFO8Moe/5f +leQ== X-Gm-Message-State: AOAM533XA4vUsvNHK4zjjGGkHFxSKFeGEy0ml6lIMPib+jRIDssrcFP1 RUQst4naD8GrZxMUWvSRn3vcow== X-Google-Smtp-Source: ABdhPJydZlPJTfW9Fx9japPRrM91W7ViFZwDYh0Bn+OTt0p4zShQTVAfBxr6Eei6JRy9XW3ipB7Z1g== X-Received: by 2002:a5d:4ecb:: with SMTP id s11mr35241509wrv.385.1619604839261; Wed, 28 Apr 2021 03:13:59 -0700 (PDT) Received: from antos (85-207-121-76.static.bluetone.cz. [85.207.121.76]) by smtp.gmail.com with ESMTPSA id t63sm3254079wma.20.2021.04.28.03.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 03:13:58 -0700 (PDT) From: Antonin Houska To: Konstantin Knizhnik cc: Daniel Gustafsson , Konstantin Knizhnik , Michael Paquier , David Steele , "ideriha.takeshi@fujitsu.com" , Jaime Casanova , Tomas Vondra , Ryan Lambert , Thomas Munro , PostgreSQL Hackers , Bruce Momjian , Dimitri Fontaine , Alvaro Herrera Subject: Re: Built-in connection pooler In-reply-to: References: <3edbc4d2-ebe8-d73f-a3f4-e043bc504f17@pgmasters.net> <20200917050711.GK2873@paquier.xyz> <0fd2ee44-e75b-8d14-4192-641aa07d6c89@postgrespro.ru> Comments: In-reply-to Konstantin Knizhnik message dated "Sun, 21 Mar 2021 21:32:28 +0300." X-Mailer: MH-E 8.6+git; nmh 1.7; GNU Emacs 26.3.50 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1914.1619604896.1@antos> Content-Transfer-Encoding: quoted-printable Date: Wed, 28 Apr 2021 12:14:56 +0200 Message-ID: <1915.1619604896@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Konstantin Knizhnik wrote: > People asked me to resubmit built-in connection pooler patch to commitfe= st. > Rebased version of connection pooler is attached. I've reviewd the patch but haven't read the entire thread thoroughly. I ho= pe that I don't duplicate many comments posted earlier by others. (Please note that the patch does not apply to the current master, I had to reset the head of my repository to the appropriate commit.) Documentation / user interface ------------------------------ * session_pool_size (config.sgml) I wonder if "The default value is 10, so up to 10 backends will serve each databas= e," should rather be "The default value is 10, so up to 10 backends will serve each databas= e/user combination." However, when I read the code, I think that each proxy counts the size of = the pool separately, so the total number of backends used for particular database/user combination seems to be session_pool_size * connection_proxies Since the feature uses shared memory statistics anyway, shouldn't it only count the total number of backends per database/user? It would need some locking, but the actual pools (hash tables) could still be local to the pr= oxy processes. * connection_proxies (I've noticed that Ryan Lambert questioned this variable upthread.) I think this variable makes the configuration less straightforward from th= e user perspective. Cannot the server launch additional proxies dynamically,= as needed, e.g. based on the shared memory statistics that the patch introduc= es? I see that postmaster would have to send the sockets in a different way. H= ow about adding a "proxy launcher" process that would take care of the schedu= ling and launching new proxies? * multitenant_proxy I thought the purpose of this setting is to reduce the number of backends needed, but could not find evidence in the code. In particular, client_attach() always retrieves the backend from the appropriate pool, an= d backend_reschedule() does so as well. Thus the role of both client and bac= kend should always match. What piece of information do I miss? * typo (2 occurrences in config.sgml) "stanalone" -> "standalone" Design / coding --------------- * proxy.c:backend_start() does not change the value of the "host" paramete= r to the socket directory, so I assume the proxy connects to the backend via = TCP protocol. I think the unix socket should be preferred for this connectio= n if the platform has it, however: * is libpq necessary for the proxy to connect to backend at all? Maybe postgres.c:ReadCommand() can be adjusted so that the backend can communi= cate with the proxy just via the plain socket. I don't like the idea of server components communicating via libpq (do w= e need anything else of the libpq connection than the socket?) as such, bu= t especially these includes in proxy.c look weird: #include "../interfaces/libpq/libpq-fe.h" #include "../interfaces/libpq/libpq-int.h" * How does the proxy recognize connections to the walsender? I haven't tes= ted that, but it's obvious that these connections should not be proxied. * ConnectionProxyState is in shared memory, so access to its fields should= be synchronized. * StartConnectionProxies() is only called from PostmasterMain(), so I'm no= t sure the proxies get restarted after crash. Perhaps PostmasterStateMachi= ne() needs to call it too after calling StartupDataBase(). * Why do you need the Channel.magic integer field? Wouldn't a boolean fiel= d "active" be sufficient? ** In proxy_loop(), I've noticed tests (chan->magic =3D=3D ACTIVE_CHANNE= L_MAGIC) tests inside the branch else if (chan->magic =3D=3D ACTIVE_CHANNEL_MAGIC) Since neither channel_write() nor channel_read() seem to change the value, I think those tests are not necessary. * Comment lines are often too long. * pgindent should be applied to the patch at some point. I can spend more time reviewing the patch during the next CF. -- = Antonin Houska Web: https://www.cybertec-postgresql.com