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 1jbswS-0002nZ-MW for pgsql-hackers@arkaria.postgresql.org; Thu, 21 May 2020 21:41:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jbswR-0003ss-JZ for pgsql-hackers@arkaria.postgresql.org; Thu, 21 May 2020 21:41:27 +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 1jbswR-0003se-C5 for pgsql-hackers@lists.postgresql.org; Thu, 21 May 2020 21:41:27 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jbswP-0003yx-4i for pgsql-hackers@postgresql.org; Thu, 21 May 2020 21:41:26 +0000 Received: by mail-ed1-x530.google.com with SMTP id d24so7741358eds.11 for ; Thu, 21 May 2020 14:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=W4+bGmqZ5LtUFHwOBebVWhz6aIcOEjc4lbH5ngkXHlI=; b=MOg1bHY3iUoQNhDQIEyZM8lULifY87UxOoJPi0wgvbEfV9xbJApXDn2hmnqVGybKam XNfvPpMl1lU8VecADimzDtcQkD5wWbmtRu5WPD8LhmlfgvUU2+ZtKXjxJoQkiTVR86A6 cFlwT5Nf0RJzX2DSNcedNJQ8ttWuLiD5AMkjAPCwrv7PQaOnF1+7UiEIFHi15oI1+Iko duiEfbXmrSPmi6C33GAWI0EVvJZ8VRvaeoUMBXQvTH2Y6gj06kXEEs5HyqmKyvMU4nSi Xz2BtZ1gRr8Gp4RDtCuV+pV8rugCOTfbHxKjihiWazCrESHX97fF6rzUkM3vGe6Jje4u yslg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=W4+bGmqZ5LtUFHwOBebVWhz6aIcOEjc4lbH5ngkXHlI=; b=VGrIfT1fV4tgBPBKepcMRKk5udM2Ffx3EXVl0vze8gbBJoXIFfdPULv72C7mROTPN/ OfPTsDNneDJKm+Bzj4tDL6sif/zuFW9cqf7Pt5N+p8CWS80OODVEXdlcGOqimNVgM61/ 6ROQBzTe16nxG/RDz/eyQeV5PTeQQE74ZaAGiD4Ws46XUO9ZrLr+3T3CJFDO7Suxhf2D RkgEX0tYwoAdDwYBTFQVE86LdwMOi83dMOSSav5Gcf99M5vmSn/iSMKaW9YybEu5qyKL rprHpntAVIV4gaDPd1l6RLmMxOJbUCKba3x/LtOdA5/M3qhkFLUN9fP8t59geI+GlPlh dYYg== X-Gm-Message-State: AOAM532VISYlxSJhL4FjMj+9410oxMBW/uxXDRmtLQKsUtaVDV7trrd/ FPNn1V7lr+2+DFJRO9cYg3cSqg== X-Google-Smtp-Source: ABdhPJzK2Ij8HjwSNYZxs0icLS+yZ05dwmGVACL3k4zcX4FSUuEHQRPuUlZ+laE1ZD46el5DfqIGSg== X-Received: by 2002:a50:d2d1:: with SMTP id q17mr674211edg.39.1590097283698; Thu, 21 May 2020 14:41:23 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id v16sm5780116ejq.74.2020.05.21.14.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 14:41:23 -0700 (PDT) Date: Thu, 21 May 2020 23:41:22 +0200 From: Tomas Vondra To: Jeff Davis Cc: pgsql-hackers@postgresql.org Subject: Re: Trouble with hashagg spill I/O pattern and costing Message-ID: <20200521214122.6opovye4mnbqczlc@development> References: <20200519151202.u2p2gpiawoaznsv2@development> <88dd39d782178539d7ee46f98b98579940e2a12e.camel@j-davis.com> <20200519175320.tl4qm6le5dbg2pcf@development> <20200521191318.gw3xjivrxracvzmg@development> <8619437df796903e64c8479e299d13ebacb5fbe0.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <8619437df796903e64c8479e299d13ebacb5fbe0.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, May 21, 2020 at 02:16:37PM -0700, Jeff Davis wrote: >On Thu, 2020-05-21 at 21:13 +0200, Tomas Vondra wrote: >> 2) We could make it self-tuning, by increasing the number of blocks >> we pre-allocate. So every time we exhaust the range, we double the >> number of blocks (with a reasonable maximum, like 1024 or so). Or we >> might just increment it by 32, or something. > >Attached a new version that uses the doubling behavior, and cleans it >up a bit. It also returns the unused prealloc blocks back to lts- >freeBlocks when the tape is rewound for reading. > Ah, the returning is a nice idea, that should limit the overhead quite a bit, I think. >> IIUC the danger of pre-allocating blocks is that we might not fill >> them, >> resulting in temp file much larger than necessary. It might be >> harmless >> on some (most?) current filesystems that don't actually allocate >> space >> for blocks that are never written, but it also confuses our >> accounting >> of temporary file sizes. So we should try to limit that, and growing >> the >> number of pre-allocated blocks over time seems reasonable. > >There's another danger here: it doesn't matter how well the filesystem >deals with sparse writes, because ltsWriteBlock fills in the holes with >zeros anyway. That's potentially a significant amount of wasted IO >effort if we aren't careful. > True. I'll give it a try on both machines and report some numbers. Might take a couple of days. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services