Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdXPQ-0002Lf-Ja for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jul 2018 08:57:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdXPO-0005DM-TW for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jul 2018 08:57:06 +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.89) (envelope-from ) id 1fdXPO-0005D7-GL for pgsql-hackers@lists.postgresql.org; Thu, 12 Jul 2018 08:57:06 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdXPK-0003sb-SN for pgsql-hackers@postgresql.org; Thu, 12 Jul 2018 08:57:05 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 7060221C26AF; Thu, 12 Jul 2018 11:57:01 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from mail.postgrespro.ru (cyclops.l.postgrespro.ru [192.168.27.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 3F30021C26A2; Thu, 12 Jul 2018 11:57:01 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1531385821; bh=rXVlUykluMX4N5WYjWx1lHBFVpy5X42dmdsEYNdqqgg=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=k2rxc3cN0er9pPiNksJnMhLP9yoUkBn7YkVHam1xiKhG5edx86jOW0W4LbI2Mu6b2 Tr7vEEM3h8P3/qURUvKzwn5K5+zNxjNmH1WDdCGaLq+Ian+IPS0kZ5SMaYer3cBY/v FD8NBdkqJFjnptFbbXMJZCrK9JKFPdSQZcBCt7no= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 12 Jul 2018 11:57:01 +0300 From: Marina Polyakova To: Alvaro Herrera Cc: Fabien COELHO , pgsql-hackers@postgresql.org, Ildus Kurbangaliev , Teodor Sigaev Subject: Re: [HACKERS] WIP Patch: Pgbench Serialization and deadlock errors Organization: Postgres Professional In-Reply-To: <20180711180417.3ytmmwmonsr5lra7@alvherre.pgsql> References: <20180711180417.3ytmmwmonsr5lra7@alvherre.pgsql> Message-ID: X-Sender: m.polyakova@postgrespro.ru User-Agent: Roundcube Webmail/1.2.4 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11-07-2018 21:04, Alvaro Herrera wrote: > Just a quick skim while refreshing what were those error reporting API > changes about ... Thank you! > On 2018-May-21, Marina Polyakova wrote: > >> v9-0001-Pgbench-errors-use-the-RandomState-structure-for-.patch >> - a patch for the RandomState structure (this is used to reset a >> client's >> random seed during the repeating of transactions after >> serialization/deadlock failures). > > LGTM, though I'd rename the random_state struct members so that it > wouldn't look as confusing. Maybe that's just me. IIUC, do you like "xseed" instead of "data"? typedef struct RandomState { - unsigned short data[3]; + unsigned short xseed[3]; } RandomState; Or do you want to rename "random_state" in the structures RetryState / CState / TState? Thanks to Fabien Coelho' comments in [1], TState can contain several RandomStates for different purposes, something like this: /* * Thread state */ typedef struct { ... /* * Separate randomness for each thread. Each thread option uses its own * random state to make all of them independent of each other and therefore * deterministic at the thread level. */ RandomState choose_script_rs; /* random state for selecting a script */ RandomState throttling_rs; /* random state for transaction throttling */ RandomState sampling_rs; /* random state for log sampling */ ... } TState; >> v9-0002-Pgbench-errors-use-the-Variables-structure-for-cl.patch >> - a patch for the Variables structure (this is used to reset client >> variables during the repeating of transactions after >> serialization/deadlock >> failures). > > Please don't allocate Variable structs one by one. First time allocate > some decent number (say 8) and then enlarge by duplicating size. That > way you save realloc overhead. We use this technique everywhere else, > no reason do different here. Other than that, LGTM. Ok! [1] https://www.postgresql.org/message-id/alpine.DEB.2.21.1806090810090.5307%40lancre > While reading your patch, it occurs to me that a run is not > deterministic > at the thread level under throttling and sampling, because the random > state is sollicited differently depending on when transaction ends. > This > suggest that maybe each thread random_state use should have its own > random > state. -- Marina Polyakova Postgres Professional: http://www.postgrespro.com The Russian Postgres Company