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 1fRlOD-0003RI-Le for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Jun 2018 21:27:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fRlOB-0000YA-Ge for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Jun 2018 21:27:11 +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 1fRlOA-0000Xz-Sc for pgsql-hackers@lists.postgresql.org; Sat, 09 Jun 2018 21:27:11 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fRlO6-0005Tp-9N for pgsql-hackers@postgresql.org; Sat, 09 Jun 2018 21:27:09 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 3831021C1C88; Sun, 10 Jun 2018 00:27:03 +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 99EE921C1C87; Sun, 10 Jun 2018 00:27:02 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1528579622; bh=luAd7/vZ388QUPhFkM7nFOCXkSjcSixWg4Wl11bO9h4=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=B2uKZu3O7XPD18dIBtn6Nbl+DTn5EFOGrXNReQmg7tvVzMgsCwmlNk6l+POY9U6p3 7pcOZ00c/S8t0TEa0xEw3wHyMJyRvgYG7OicokVoruXI6nxjJBtptF0T+nWlv/NiyE iKJBsvAuXMCNp4UIiGTZtZl0znWiOa/RyRHpyFNI= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 10 Jun 2018 00:27:02 +0300 From: Marina Polyakova To: Fabien COELHO Cc: Alvaro Herrera , pgsql-hackers@postgresql.org, Ildus Kurbangaliev , Teodor Sigaev Subject: Re: [HACKERS] WIP Patch: Pgbench Serialization and deadlock errors Organization: Postgres Professional In-Reply-To: References: <20180508193621.dphlgwrd5yz67o2z@alvherre.pgsql> <0569c5309cf536a839e2a3a1433bd113@postgrespro.ru> Message-ID: <66cba8455d0c1d5b1bbd4f15f379bbd8@postgrespro.ru> 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 09-06-2018 9:55, Fabien COELHO wrote: > Hello Marina, Hello! >> 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). > > A few comments about this first patch. Thank you very much! > Patch applies cleanly, compiles, global & pgbench "make check" ok. > > I'm mostly ok with the changes, which cleanly separate the different > use of random between threads (script choice, throttle delay, > sampling...) and client (random*() calls). Glad to hear it :) > This change is necessary so that a client can restart a transaction > deterministically (at the client level at least), which is the > ultimate aim of the patch series. > > A few remarks: > > The RandomState struct is 6 bytes, which will induce some padding when > used. This is life and pre-existing. No problem. > > ISTM that the struct itself does not need a name, ie. "typedef struct > { ... } RandomState" is enough. Ok! > There could be clear comments, say in the TState and CState structs, > about what randomness is impacted (i.e. script choices, etc.). Thank you, I'll add them. > getZipfianRand, computeHarmonicZipfian: The "thread" parameter was > justified because it was used for two fieds. As the random state is > separated, I'd suggest that the other argument should be a zipfcache > pointer. I agree with you and I will change it. > 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. Thank you, I'll fix this. > In passing, and totally unrelated to this patch: > > I've always been a little puzzled about why a quite small 48-bit > internal state random generator is used. I understand the need for pg > to have a portable & state-controlled thread-safe random generator, > but why this particular small one fails me. The source code > (src/port/erand48.c, copyright in 1993...) looks optimized for 16 bits > architectures, which is probably pretty inefficent to run on 64 bits > architectures. Maybe this could be updated with something more > consistent with today's processors, providing more quality at a lower > cost. This sounds interesting, thanks! *went to look for a multiplier and a summand that are large enough and are mutually prime..* -- Marina Polyakova Postgres Professional: http://www.postgrespro.com The Russian Postgres Company