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 1q9slr-0004De-Fb for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jun 2023 19:36:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q9slq-0004zq-CK for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jun 2023 19:36:38 +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 1q9slp-0004yV-Vp for pgsql-hackers@lists.postgresql.org; Thu, 15 Jun 2023 19:36:38 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q9sln-002P0v-08 for pgsql-hackers@postgresql.org; Thu, 15 Jun 2023 19:36:36 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-30af159b433so7987770f8f.3 for ; Thu, 15 Jun 2023 12:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garret-ru.20221208.gappssmtp.com; s=20221208; t=1686857793; x=1689449793; 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=oCj2uYj7MoEf0/c2RPCSHhoSCTeVMw+AuMbjvQ/E70g=; b=PR1LnjwzatVFPlclWe1FksrkzqNkCDKdr6dT/VVH8aHwhpPbQVAbKlxtbJV5bS9Fdu iYR3QdSnJXieq6IG1Ac8+El+LBFWgEFA8JYTzqU1KG5/c/ulXzlKy2zkWBOtc2DCZpWm OXTHmhIGzZ4B+Z0X3ZbBmWYSRMtbVxye6WmXjbqEzrAmPLSxIUJuHT+yZspbFwl9s6Ch h1cYNxSBsVLCiz46CNt2nvC7HqJrz8Hi5sv4MxuGx0YlC1iAPEIxrp2Q60tUK7tUbpFF i6mSDNFoUqVZX9WOYwaV4vzHNRzKQnCi3DFs5IEL7ONnEXJ6vX/kFEuVPIcpA5zNRkb6 YB2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686857793; x=1689449793; 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=oCj2uYj7MoEf0/c2RPCSHhoSCTeVMw+AuMbjvQ/E70g=; b=L3rvuKQwK/n4sVvjfil9IHbq62ItICX7Rv/cBHK7L+Ci1zUJMxqpqUFtYp77Ztq6qv dP5T4Pc0+8AirQ+Ua1+LiNMPl+EQ4iA5GNDx/A+VXOrSibfKn0gtt/ld+LqEi9ZkiHxS QIp3TmSQ3dP4SkheKZxgJfLCRVjAPO2myhM3FyOiYOWn3lNba6hgKF7iKYH2ZsOPq8bY AFZgSnfVwtF0380WjhGGudKYeLS5nm/AfpsBwpqGxUe0KF1OwbvbV6TzkNYYWf6CCBE/ C9FAr0+4pMFzwRncjTGvFeKtIaWFFjboloWRRDMJIxZI3TGAs7nh3I5C7Le9lnSaa00P pIYQ== X-Gm-Message-State: AC+VfDyXCZ69frUwwCdckjSNhpuonkuwSMUTzjLnG4HG7bdI/ybJ+pSO 1ssdj/+VbzQhs+TjV8GyG9/E5A== X-Google-Smtp-Source: ACHHUZ76TFVLuEVKcvR+6OXzEuoYIgzupL1b8jTA4JLyo/JvgphH0U/9FFzJ6rmYMybwYHPfZMh64g== X-Received: by 2002:adf:f3c4:0:b0:309:48ec:2c82 with SMTP id g4-20020adff3c4000000b0030948ec2c82mr13817991wrp.48.1686857793107; Thu, 15 Jun 2023 12:36:33 -0700 (PDT) Received: from [192.168.2.28] ([217.175.216.56]) by smtp.gmail.com with ESMTPSA id i1-20020a5d4381000000b0030c4d8930b1sm21697291wrq.91.2023.06.15.12.36.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Jun 2023 12:36:32 -0700 (PDT) Message-ID: <67370d03-9244-c7eb-1b87-8052659457ba@garret.ru> Date: Thu, 15 Jun 2023 22:36:30 +0300 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: James Addison Cc: Pavel Borisov , Dilip Kumar , Hannu Krosing , Heikki Linnakangas , pgsql-hackers References: <31cc6df9-53fe-3cd9-af5b-ac0d801163f4@iki.fi> <2c2665d2-c513-c12e-9097-9b1805bc2471@garret.ru> <36f61a71-3bbb-b7b0-0d99-db5e69715af7@garret.ru> From: Konstantin Knizhnik In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 15.06.2023 11:41 AM, James Addison wrote: > On Thu, 15 Jun 2023 at 08:12, Konstantin Knizhnik wrote: >> >> >> On 15.06.2023 1:23 AM, James Addison wrote: >> >> On Tue, 13 Jun 2023 at 07:55, Konstantin Knizhnik wrote: >> >> >> On 12.06.2023 3:23 PM, Pavel Borisov wrote: >> >> Is the following true or not? >> >> 1. If we switch processes to threads but leave the amount of session >> local variables unchanged, there would be hardly any performance gain. >> 2. If we move some backend's local variables into shared memory then >> the performance gain would be very near to what we get with threads >> having equal amount of session-local variables. >> >> In other words, the overall goal in principle is to gain from less >> memory copying wherever it doesn't add the burden of locks for >> concurrent variables access? >> >> Regards, >> Pavel Borisov, >> Supabase >> >> >> IMHO both statements are not true. >> Switching to threads will cause less context switch overhead (because >> all threads are sharing the same memory space and so preserve TLB. >> How big will be this advantage? In my prototype I got ~10%. But may be >> it is possible to fin workloads when it is larger. >> >> Hi Konstantin - do you have code/links that you can share for the >> prototype and benchmarks used to gather those results? >> >> >> >> Sorry, I have already shared the link: >> https://github.com/postgrespro/postgresql.pthreads/ > Nope, my mistake for not locating the existing link - thank you. > > Is there a reason that parser-related files (flex/bison) are added as > part of the changeset? (I'm trying to narrow it down to only the > changes necessary for the functionality. so far it looks mostly > fairly minimal, which is good. the adjustments to progname are > another thing that look a bit unusual/maybe unnecessary for the > feature) Sorry, absolutely no reason - just my fault. >> As you can see last commit was 6 years ago when I stopped work on this project. >> Why? I already tried to explain it: >> - benefits from switching to threads were not so large. May be I just failed to fid proper workload, but is was more or less expected result, >> because most of the code was not changed - it uses the same sync primitives, the same local catalog/relation caches,.. >> To take all advantage of multithreadig model it is necessary to rewrite many components, especially related with interprocess communication. >> But maintaining such fork of Postgres and synchronize it with mainstream requires too much efforts and I was not able to do it myself. > I get the feeling that there are probably certain query types or > patterns where a significant, order-of-magnitude speedup is possible > with threads - but yep, I haven't seen those described in detail yet > on the mailing list (but as hinted by my not noticing the github link > previously, maybe I'm not following the list closely enough). > > What workloads did you try with your version of the project? I do not remember now precisely (6 years passed). But definitely I tried pgbench, especially read-only pgbench (to be more CPU rather than disk bounded)