Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZO9R-0006iL-88 for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Dec 2018 22:47:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZO9P-0003GL-GN for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Dec 2018 22:47:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZO9P-0003GE-61 for pgsql-hackers@lists.postgresql.org; Tue, 18 Dec 2018 22:47:43 +0000 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZO9M-0008F5-41 for pgsql-hackers@postgresql.org; Tue, 18 Dec 2018 22:47:42 +0000 Received: by mail-qt1-x844.google.com with SMTP id t33so17426266qtt.4 for ; Tue, 18 Dec 2018 14:47:39 -0800 (PST) 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:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=/J3IJU6jPRrLxc5YKk4AeehrqurDPzXl8DDs//P/pJU=; b=W9Dr9rO+3G1tpYp+9bzkDJzmFqmKrUiiUqrIRD3MMdmtooX9bvzHbYrp3TsL4jfvkf XjTZqt7XqzSh0F7J2zqDo/Bt04nRXzZKYOCBSha/hChr6a7MV/GYgqV9n8DxT5hesGPm jCBfEqb5so4JPjuwzmpPc0SnGYP2Ix1WGgewJSZAIGFiA2Kf18cbqjCwod76eaG+eM4l V/xEDz9BWj225riPs+S1sH76966RNUYmoH2i+BGPdghZ8dyt42YWaP5Q/9c9v7+NMbu5 /JHXz4zYw82xY7IEN+GRZ4KI3hcZYyIgPJIQUZjZvJ6ZZfDbeZkQSUA2IfEC9wT9iRnb +LJA== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=/J3IJU6jPRrLxc5YKk4AeehrqurDPzXl8DDs//P/pJU=; b=O/4WM5QkB2D+Htp30wCJ9gucictZZaJfNfl7Q5F8BnrH9UF78lLznUDKVNZepN/D6X NzKQU7HA6iER3oywNTtX1Hgv6nfNiNIuEnJ8CQIcZxkWrXuQFKtBdLMNRvkAu4kAU2BZ WswwErBkinvVPzTAh5s/JjcWf/1wfbikwFX3mIP1gk8iE5mrf1WzlwNNVmrNaPqMdxUm yzSW4nu/LE6OLjfw/D6Qb1ZmyWTVIUCqCv0eILYB6mhmfKK1DLZrvQXo9h5P7pkZ4YnC D1+pmqaQ7Dd4D8JsfXBDm1e5OQmkXtwY4w4C6JgSv3PB2+cK336cn9yb6r9BuqU91Qn2 Vqkg== X-Gm-Message-State: AA+aEWbOHS3xMT3k8Bnz2XAICccRvivmV8c7wYJwpClunGJlVpW7ZVdM +rPweqUAJ4cTnaF78ca8LUzbNg== X-Google-Smtp-Source: AFSGD/WaJO6kZKp1D3kwM0w+Y2YaVloggDUZ3wefUv8dsa0qKsLPb9oy+4kE3laYZKlAcX55N26hfw== X-Received: by 2002:ac8:33fc:: with SMTP id d57mr18819649qtb.82.1545173258662; Tue, 18 Dec 2018 14:47:38 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id n72sm1186848qki.26.2018.12.18.14.47.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 18 Dec 2018 14:47:38 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 0CD277E4; Tue, 18 Dec 2018 19:47:36 -0300 (-03) Date: Tue, 18 Dec 2018 19:47:36 -0300 From: Alvaro Herrera To: Peter Geoghegan Cc: Robert Haas , Tatsuro Yamada , "pgsql-hackers@postgresql.org" Subject: Re: [HACKERS] CLUSTER command progress monitor Message-ID: <20181218224736.6e5jakieqigjlt7f@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018-Dec-18, Peter Geoghegan wrote: > On Tue, Dec 18, 2018 at 1:02 PM Alvaro Herrera wrote: > > If we see this in terms of tapes and merges, we can report the total > > number of each of those that we have completed. As far as I understand, > > we write one tape to completion, and only then start another one, right? > > Since there's no way to know how many tapes/merges are needed in total, > > it's not possible to compute a percentage of completion. That's seems > > okay -- we're just telling the user that progress is being made, and we > > only report facts not theory. Perhaps we can (also?) indicate disk I/O > > utilization, in terms of the number of blocks written by tuplesort. > > The number of blocks tuplesort uses is constant from the end of > initial run generation, since logtape.c will recycle blocks. Well, if you think about individual blocks in terms of storage space, maybe that's true, but I meant in an Heraclitus way of men never stepping into the same river -- the second time you write the block, it's not the same block you wrote before, so you count it twice. It's not the actual disk space utilization that matters, but how much I/O have you done (even if it is just to kernel cache, I suppose). > > I suppose that in order to have tuplesort.c report progress, we would > > have to have some kind of API that tuplesort would invoke internally to > > indicate events such as "tape started/completed", "merge started/completed". > > One idea is to use a callback system; each tuplesort caller could > > optionally pass a callback to the "begin" function, for progress > > reporting purposes. Initially only cluster.c would use it, but I > > suppose eventually every tuplesort caller would want that. > > I think that you could have a callback that did something with the > information currently reported by trace_sort. That's not a bad way of > scoping the problem. That's how I myself monitor the progress of a > sort, and it works pretty well (whether or not that means other people > can do it is not exactly clear to me). Thanks, that looks useful. I suppose mapping such numbers to actual progress is a bit of an art (or intuition as you say), but it seems to be the best we can do, if we do anything at all. > We predict the number of merge passes within cost_sort() already. That > doesn't seem all that hard to generalize, so that you report the > expected number of passes against the current pass. Some passes are > much quicker than others, but you generally don't have that many with > realistic cases. I don't expect that it will work very well with an > internal sort, but in the case of CLUSTER that almost seems > irrelevant. And maybe even in all cases. How good are those predictions? The feeling I get from this thread is that if the estimation of the number of passes is unreliable, it's better not to report it at all; just return how many we've done thus far. It's undesirable to report that we're about 150% done (or take hours to get to 40% done, then suddenly be over). I wonder if internal sorts are really all that interesting from the PoV of progress reporting. Also, I have the impression that quicksort isn't very amenable to letting you know how much work is left. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services