Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yoe3V-0001HF-8I for pgsql-hackers@arkaria.postgresql.org; Sat, 02 May 2015 20:30:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yoe3U-0006p6-Bg for pgsql-hackers@arkaria.postgresql.org; Sat, 02 May 2015 20:30:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yoe3S-0006ov-AA for pgsql-hackers@postgresql.org; Sat, 02 May 2015 20:30:30 +0000 Received: from jiboia.ensmp.fr ([194.214.158.103]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Yoe3J-0002pS-9f for pgsql-hackers@postgresql.org; Sat, 02 May 2015 20:30:29 +0000 Received: from cri.ensmp.fr ([94.124.155.245]) (authenticated bits=0) by jiboia.ensmp.fr (8.14.9/8.14.9/JMMC-22/Oct/2013) with ESMTP id t42KU9kH017067 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 2 May 2015 22:30:18 +0200 Date: Sat, 2 May 2015 16:30:08 -0400 (AST) From: Fabien COELHO X-X-Sender: fabien@sto To: Tomas Vondra cc: PostgreSQL Developers Subject: Re: PATCH: pgbench - merging transaction logs In-Reply-To: <5544F8EC.6030908@2ndquadrant.com> Message-ID: References: <54FCB11B.5050907@2ndquadrant.com> <5505CF30.7030308@2ndquadrant.com> <550CCBE5.8060009@2ndquadrant.com> <551730E9.108@2ndquadrant.com> <5519F65F.7040005@2ndquadrant.com> <5544F8EC.6030908@2ndquadrant.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-Miltered: at jiboia.ensmp.fr with ID 554533D1.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: 554533D1.000 from [94.124.155.245]/[94.124.155.245]/94.124.155.245/cri.ensmp.fr/ X-Pg-Spam-Score: -1.9 (-) 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 > It might be done in the other direction, though - the "writer" thread > might collect current results at the end of the interval. Yep, you can indeed accumulate per thread and sum on the end of the interval, but a lock is still needed if you want exact figures. ISTM that it is what is done for --progress, without even bothering to lock anything (even if transactions are fast and some inconsistency arise, this is just for showing how things are faring on stderr, so no big deal). >> "fprintf" does a lot of processing, so it is the main issue. > > The question is whether the processing happens while holding the lock, > though. I don't think that's the case. Alas I'm pretty nearly sure it is necessarily the case, there is no intermediate buffer in fprintf, the buffering is done trough the file handler so a lock must be acquire throughout format processing. https://www.gnu.org/software/libc/manual/html_node/Streams-and-Threads.html#Streams-and-Threads "The POSIX standard requires that by default the stream operations are atomic. I.e., issuing two stream operations for the same stream in two threads at the same time will cause the operations to be executed as if they were issued sequentially. The buffer operations performed while reading or writing are protected from other uses of the same stream. To do this each stream has an internal lock object which has to be (implicitly) acquired before any work can be done. " -- Fabien. -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers