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 1mC9vP-0003Eb-QO for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Aug 2021 00:10:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mC9vO-0005bY-EA for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Aug 2021 00:10:50 +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 1mC9vN-0005ZC-L0 for pgsql-hackers@lists.postgresql.org; Sat, 07 Aug 2021 00:10:50 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mC9vG-0001Cs-BE for pgsql-hackers@lists.postgresql.org; Sat, 07 Aug 2021 00:10:48 +0000 Received: by mail-wm1-x335.google.com with SMTP id m36-20020a05600c3b24b02902e67543e17aso31553wms.0 for ; Fri, 06 Aug 2021 17:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=RyerVWqJZOjAGjxcnW2WVFLVUfvlw6vGVsmqpKzz/Q8=; b=LUvRh/HrB4IA9LhGFWclI0EHIbIlcyCSIMx+SN+FlM0Yj5148Jq6fekFiLXsbCW0AB /Io+x6lL2kA9lZUSTA3W2Le4doHxowEoXzw62jEPDNeXRjkmkwpoMVeM/sZtRS/Sf4zB SWB+aRq6LQNIg2B+Y4nKHqfJLx7EHNqzgFh0VDY7+a9x8T/zHHvxrlYnRDITFXuaen5X ze94DsS2gxNTEUq56PulSa/0+v703c0gSiYQkroIUGJ/UHJSbbyCeQAeRtyQpKOLvPOK BmG36HhaioJCJBug03Fv1GU+98B/asYmEm84ea0Q7j/IkE3cE6uWSzzGliu3jchKjqh8 85vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=RyerVWqJZOjAGjxcnW2WVFLVUfvlw6vGVsmqpKzz/Q8=; b=Z+wfT2PVdEtxVOJ5IXrgsX6oT3vykDf/+mfcNOwMiUlFh/+Ax0/TDlzvhC+u92t8uh EBbiESYEY9EMimLh+lcJhUHNehsc8r0NRNlqQqqw/JeuS2gjQwT9htdj2oWWTxOYIZpR 9DL0uwGLH9oxAQgylFFHaOcIbTVRl3pBo57uPHIne0rtvHCF87/7fcZRLs121W/8AsLi k4sSjNaviQdcdaA3KfBQKBv4fvNrsLDGQ8rl2u+d3ViOB34mHo5XIry0X6zEA1/MpE2w 33aP3/5iDokA1muPymXOjOOZPK/eUjdmiOCKPveNY7k5zIh2l4ypxZwZt1tARfpdpMwc PmMQ== X-Gm-Message-State: AOAM533ZhdYnfiI/kk+HIovduPW70RYxJDOCBe2PSrCYqj8+lTwIY1+J 9krBZk+plbra5TYWQN20OWK+OpxWklcijPocnigHu2Vy+4c3btwpsFADt7O2WYhzvho26o+fJgY m5ALGh/SwpGV+6ouoMXGZTdf2o4JCx6XRXxfAxUfx7jihqNHLAJNMRsmjeM2ZTkt8Geg37VUXaX BABeaVv6EqJkVLFG0EOHmuUaUxt+lo6m+pFrhSc1oyMs0yeCTAdDn2yjqjjx2QLT/VjrcKgI+3K XvTsbB//xi9gAYp01RllajALJTKgMSQhEH9mM8Uy6pmpmJ+7WJsrNF1 X-Google-Smtp-Source: ABdhPJw/DvmmJcQuFXBv5FzR0uIAvS+zGOTLDxPdW+pHFGDPzQ+caGdjnw+h7WahGPYYVhMw/qm+Ow== X-Received: by 2002:a1c:95:: with SMTP id 143mr5705687wma.29.1628295039880; Fri, 06 Aug 2021 17:10:39 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-254-183.net.upcbroadband.cz. [86.49.254.183]) by smtp.gmail.com with ESMTPSA id z2sm9935682wma.45.2021.08.06.17.10.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Aug 2021 17:10:39 -0700 (PDT) Subject: Re: Use generation context to speed up tuplesorts To: David Rowley Cc: Andres Freund , Tomas Vondra , PostgreSQL Developers References: <20210730203853.utjj43f6zzn5e2hy@alap3.anarazel.de> <36829a8a-63d0-c428-89d5-07e49561973e@enterprisedb.com> From: Tomas Vondra Message-ID: <13808af0-2bb5-b506-62d0-1fb67e3385d0@enterprisedb.com> Date: Sat, 7 Aug 2021 02:10:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/6/21 3:07 PM, David Rowley wrote: > On Wed, 4 Aug 2021 at 02:10, Tomas Vondra wrote: >> A review would be nice, although it can wait - It'd be interesting to >> know if those patches help with the workload(s) you've been looking at. > > I tried out the v2 set of patches using the attached scripts. The > attached spreadsheet includes the original tests and compares master > with the patch which uses the generation context vs that patch plus > your v2 patch. > > I've also included 4 additional tests, each of which starts with a 1 > column table and then adds another 32 columns testing the performance > after adding each additional column. I did this because I wanted to > see if the performance was more similar to master when the allocations > had less power of 2 wastage from allocset. If, for example, you look > at row 123 of the spreadsheet you can see both patched and unpatched > the allocations were 272 bytes each yet there was still a 50% > performance improvement with just the generation context patch when > compared to master. > > Looking at the spreadsheet, you'll also notice that in the 2 column > test of each of the 4 new tests the number of bytes used for each > allocation is larger with the generation context. 56 vs 48. This is > due to the GenerationChunk struct size being later than the Allocset's > version by 8 bytes. This is because it also holds the > GenerationBlock. So with the patch there are some cases where we'll > use slightly more memory. > > Additional tests: > > 1. Sort 10000 tuples on a column with values 0-99 in memory. > 2. As #1 but with 1 million tuples. > 3 As #1 but with a large OFFSET to remove the overhead of sending to the client. > 4. As #2 but with a large OFFSET. > > Test #3 above is the most similar one to the original tests and shows > similar gains. When the sort becomes larger (1 million tuple test), > the gains reduce. This indicates the gains are coming from improved > CPU cache efficiency from the removal of the power of 2 wastage in > memory allocations. > > All of the tests show that the patches to improve the allocation > efficiency of generation.c don't help to improve the results of the > test cases. I wondered if it's maybe worth trying to see what happens > if instead of doubling the allocations each time, quadruple them > instead. I didn't try this. > Thanks for the scripts and the spreadsheet with results. I doubt quadrupling the allocations won't help very much, but I suspect the problem might be in the 0004 patch - at least that's what shows regression in my results. Could you try with just 0001-0003 applied? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company