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 1q6yhl-00076x-9p for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jun 2023 19:20:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q6yhk-0000SC-69 for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jun 2023 19:20:24 +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 1q6yhj-0000Rw-SJ for pgsql-hackers@lists.postgresql.org; Wed, 07 Jun 2023 19:20:23 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q6yhf-000lHu-Kz for pgsql-hackers@postgresql.org; Wed, 07 Jun 2023 19:20:22 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5149390b20aso2233428a12.3 for ; Wed, 07 Jun 2023 12:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1686165617; x=1688757617; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=oHGYvCqr8Hd2jHYY4S0Q7Oau52kkJ3D/A4WvT1mB8V0=; b=CyNjgrzO2KuMLlsnC5ZM+4RNwrm/AMVzPXDZjEcCyS6AXqiMgtOi0dQ7iOnSKY79fT Vn8TbJZ2hl64pZ3ndS2Rkmw1wsAZRei9OBW88AjgSyA8n6zjaVfqrH10/9zu6pRb/7Z2 2Nsn0bMOqergr3/NgydWT7ywPfHrP/5HdJD4dgnO+jz1HJok6WXVhe3YTPX8lAc/sV/9 eaNVohompZQeBXDEyFz4fhkSGzjcTi2MQqamz9CIGAv7xR6Jskh5InPr73hN8dHzFYcb Gk87EaIs1C+OQnhQcXcK7JYvB+NTZplvzGVVVUrSy4fDujB+eWXmJ6h41jljg2lmyzJb 4VZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686165617; x=1688757617; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oHGYvCqr8Hd2jHYY4S0Q7Oau52kkJ3D/A4WvT1mB8V0=; b=EYCEaymM1l4PqtAOjmBqZGalVZhwotzw7GJiuI5eZeqiMsMa9xUp94XbTdP9xkjy5C 7giMvtbbl5o5f7c+eKR0Q33p4XeD/sdf5qKZy2UhZ/3U4nKo1GNdhsSdgJc5uOGTYbCL KELW+oBQvPPznEljTtoXCd7MqlBEWGTNocQzEKS/SuUlk/8oQP4d0lbKTh+Cao8jIOAu /qrIUf+vhdh4HQz6juAfuT6dQf5A8NGkCgUK1SL9b74Qg04IFdoUQUjSinYGgX/9x3VJ a7f5+8UraroxNInF8oCxH+kllT5w7az2n/aqS6YuN7hR/b/7P67R8yM8QTDbmR4lBmV1 s6HA== X-Gm-Message-State: AC+VfDzjb0SzQg759SXNrRWKzRyTd88ZLex4kEEeqTcumpNHintqXR1f ubIe6ZaPie4bg6KlJmM1786qTg== X-Google-Smtp-Source: ACHHUZ6VXhekaIxQvyGhfcT4YYPuKdwse46NVKaeblpQtWszw19C9ekvNmOoqIcU7jI5KIWjeGB26w== X-Received: by 2002:aa7:d697:0:b0:510:8ee2:2b05 with SMTP id d23-20020aa7d697000000b005108ee22b05mr4817219edr.38.1686165617412; Wed, 07 Jun 2023 12:20:17 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-228-220.bb.vodafone.cz. [86.49.228.220]) by smtp.gmail.com with ESMTPSA id w15-20020a056402070f00b00514bb73b8casm6665336edx.57.2023.06.07.12.20.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Jun 2023 12:20:16 -0700 (PDT) Message-ID: <29fe5f48-a6ed-d896-45ed-16b5904353a9@enterprisedb.com> Date: Wed, 7 Jun 2023 21:20:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: Let's make PostgreSQL multi-threaded Content-Language: en-US To: Heikki Linnakangas , Tom Lane Cc: pgsql-hackers References: <31cc6df9-53fe-3cd9-af5b-ac0d801163f4@iki.fi> <4178104.1685978307@sss.pgh.pa.us> <4ce6c0f8-e8a4-1672-93fd-49d3fa975ee5@iki.fi> From: Tomas Vondra In-Reply-To: <4ce6c0f8-e8a4-1672-93fd-49d3fa975ee5@iki.fi> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/5/23 17:33, Heikki Linnakangas wrote: > On 05/06/2023 11:18, Tom Lane wrote: >> Heikki Linnakangas writes: >>> I spoke with some folks at PGCon about making PostgreSQL multi-threaded, >>> so that the whole server runs in a single process, with multiple >>> threads. It has been discussed many times in the past, last thread on >>> pgsql-hackers was back in 2017 when Konstantin made some experiments >>> [0]. >> >>> I feel that there is now pretty strong consensus that it would be a good >>> thing, more so than before. Lots of work to get there, and lots of >>> details to be hashed out, but no objections to the idea at a high level. >> >>> The purpose of this email is to make that silent consensus explicit. If >>> you have objections to switching from the current multi-process >>> architecture to a single-process, multi-threaded architecture, please >>> speak up. >> >> For the record, I think this will be a disaster.  There is far too much >> code that will get broken, largely silently, and much of it is not >> under our control. > > Noted. Other large projects have gone through this transition. It's not > easy, but it's a lot easier now than it was 10 years ago. The platform > and compiler support is there now, all libraries have thread-safe > interfaces, etc. > Is the platform support really there for all platforms we want/intend to support? I have no problem believing that for modern Linux/BSD systems, but what about the older stuff we currently support. Also, which other projects did this transition? Is there something we could learn from them? Were they restricted to much smaller list of platforms? > I don't expect you or others to buy into any particular code change at > this point, or to contribute time into it. Just to accept that it's a > worthwhile goal. If the implementation turns out to be a disaster, then > it won't be accepted, of course. But I'm optimistic. > I personally am not opposed to the effort in principle, but how do you even evaluate cost and benefits for a transition like this? I have no idea how to quantify the costs/benefits for this as a single change. I've seen some benchmarks in the past, but it's hard to say which of these improvements are possible only with threads, and what would be doable with less invasive changes with the process model. IMHO the only way to move this forward is to divide this into smaller changes, each of which gives us some benefit we'd want anyway. For example, this thread already mentioned improving handling of many connections. AFAICS that requires isolating "session state", which seems useful even without a full switch to threads as it makes connection pooling simpler. It should be easier to get a buy-in for these changes, while introducing abstractions simplifying the switch to threads. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company