Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bNFL6-0006CL-O0 for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jul 2016 08:16:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bNFL4-0006sD-Tn for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jul 2016 08:16:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bNFJh-0005IY-JM for pgsql-hackers@postgresql.org; Wed, 13 Jul 2016 08:14:49 +0000 Received: from jiboia.ensmp.fr ([194.214.158.137]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bNFJd-0007nl-5u for pgsql-hackers@postgresql.org; Wed, 13 Jul 2016 08:14:47 +0000 Received: from cri.ensmp.fr (AGrenoble-653-1-69-83.w92-129.abo.wanadoo.fr [92.129.7.83]) (authenticated bits=0) by jiboia.ensmp.fr (8.15.2/8.15.1/JMMC-22/Oct/2013) with ESMTPSA id u6D8EaaW002603 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 13 Jul 2016 10:14:40 +0200 Date: Wed, 13 Jul 2016 10:14:36 +0200 (CEST) From: Fabien COELHO X-X-Sender: fabien@sto To: Tom Lane cc: Michael Paquier , PostgreSQL Developers Subject: Re: pgbench - minor fix for meta command only scripts In-Reply-To: <6016.1468357163@sss.pgh.pa.us> Message-ID: References: <6016.1468357163@sss.pgh.pa.us> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-405969968-1468397680=:7486" X-Miltered: at jiboia.ensmp.fr with ID 5785F86C.000 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-j-chkmail-Auth: USER-ID fabien.coelho X-j-chkmail-Enveloppe: 5785F86C.000 from AGrenoble-653-1-69-83.w92-129.abo.wanadoo.fr/AGrenoble-653-1-69-83.w92-129.abo.wanadoo.fr/92.129.7.83/cri.ensmp.fr/ X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-405969968-1468397680=:7486 Content-Type: text/plain; charset=US-ASCII; format=flowed Hello Tom, >> Ok. Here is an updated version, with a better suffix and a simplified >> comment. > > Doesn't this break the handling of latency calculations, or at least make > the results completely different for the last metacommand than what they > would be for a non-last command? It looks like it needs to loop back so > that the latency calculation is completed for the metacommand before it > can exit. Seems to me it would probably make more sense to fall out at > the end of the "transaction finished" if-block, around line 1923 in HEAD. Indeed, it would trouble a little bit the stats computation by delaying the recording of the end of statement & transaction. However line 1923 is a shortcut for ending pgbench, but at the end of a transaction more stuff must be done, eg choosing the next script and reconnecting, before exiting. The solution is more contrived. The attached patch provides a solution which ensures the return in the right condition and after the stat collection. The code structure requires another ugly boolean to proceed so as to preserve doing the reconnection between the decision that the return must be done and the place where it can be done, after reconnecting. > (The code structure in here seems like a complete mess to me, but probably > now is not the time to refactor it.) I fully agree that the code structure is a total mess:-( Maybe I'll try to submit a simpler one some day. Basically the doCustom function is not resilient, you cannot exit from anywhere and hope that re-entring would achieve a consistent behavior. While reading the code to find a better place for a return, I noted some possible inconsistencies in recording stats, which are noted as comments in the attached patch. Calling chooseScript is done both from outside for initialization and from inside doCustom, where it could be done once and more clearly in doCustom. Boolean listen is not reset because the script is expected to execute directly the start of the next statement. I succeeded in convincing myself that it actually works, but it is unobvious to spot why. I think that a simpler pattern would be welcome. Also, some other things (eg prepared) are not reset in all cases, not sure why. The goto should probably be replaced by a while. ... -- Fabien. --8323329-405969968-1468397680=:7486 Content-Type: text/x-diff; name=pgbench-latency-t-2.patch Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=pgbench-latency-t-2.patch ZGlmZiAtLWdpdCBhL3NyYy9iaW4vcGdiZW5jaC9wZ2JlbmNoLmMgYi9zcmMv YmluL3BnYmVuY2gvcGdiZW5jaC5jDQppbmRleCA4N2ZiMDA2Li44YzVkZjE0 IDEwMDY0NA0KLS0tIGEvc3JjL2Jpbi9wZ2JlbmNoL3BnYmVuY2guYw0KKysr IGIvc3JjL2Jpbi9wZ2JlbmNoL3BnYmVuY2guYw0KQEAgLTE3NjYsNyArMTc2 Niw4IEBAIGRvQ3VzdG9tKFRTdGF0ZSAqdGhyZWFkLCBDU3RhdGUgKnN0LCBT dGF0c0RhdGEgKmFnZykNCiB7DQogCVBHcmVzdWx0ICAgKnJlczsNCiAJQ29t bWFuZCAgICoqY29tbWFuZHM7DQotCWJvb2wJCXRyYW5zX25lZWRzX3Rocm90 dGxlID0gZmFsc2U7DQorCWJvb2wJCXRyYW5zX25lZWRzX3Rocm90dGxlID0g ZmFsc2UsDQorCQkJCXJldHVybl9iZWZvcmVfbmV4dF90cmFucyA9IGZhbHNl Ow0KIAlpbnN0cl90aW1lCW5vdzsNCiANCiAJLyoNCkBAIC0xODQ5LDYgKzE4 NTAsOCBAQCB0b3A6DQogDQogCWlmIChzdC0+bGlzdGVuKQ0KIAl7CQkJCQkJ CS8qIGFyZSB3ZSByZWNlaXZlcj8gKi8NCisJCWJvb2wgbGlzdGVuZWRfYV9t ZXRhID0gY29tbWFuZHNbc3QtPnN0YXRlXS0+dHlwZSA9PSBNRVRBX0NPTU1B TkQ7DQorDQogCQlpZiAoY29tbWFuZHNbc3QtPnN0YXRlXS0+dHlwZSA9PSBT UUxfQ09NTUFORCkNCiAJCXsNCiAJCQlpZiAoZGVidWcpDQpAQCAtMTg5Miw2 ICsxODk1LDcgQEAgdG9wOg0KIAkJCS8qDQog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EAgLTE5NjksNiArMTk3OSwxMCBAQCB0b3A6DQog CQltZW1zZXQoc3QtPnByZXBhcmVkLCAwLCBzaXplb2Yoc3QtPnByZXBhcmVk KSk7DQogCX0NCiANCisJLyogZW5zdXJlIHRoYXQgbWV0YS1vbmx5IHNjcmlw dHMgc29tZXRpbWVzIHJldHVybiAqLw0KKwlpZiAocmV0dXJuX2JlZm9yZV9u ZXh0X3RyYW5zKQ0KKwkJcmV0dXJuIHRydWU7DQorDQogCS8qDQogCSAqIFRo aXMgZW5zdXJlcyB0aGF0IGEgdGhyb3R0bGluZyBkZWxheSBpcyBpbnNlcnRl ZCBiZWZvcmUgcHJvY2VlZGluZyB3aXRoDQogCSAqIHNxbCBjb21tYW5kcywg YWZ0ZXIgdGhlIGZpcnN0IHRyYW5zYWN0aW9uLiBUaGUgZmlyc3QgdHJhbnNh Y3Rpb24NCg== --8323329-405969968-1468397680=:7486 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --8323329-405969968-1468397680=:7486--