Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YZPBb-0001QV-Jh for pgsql-hackers@arkaria.postgresql.org; Sat, 21 Mar 2015 19:35:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YZPBa-00068l-7r for pgsql-hackers@arkaria.postgresql.org; Sat, 21 Mar 2015 19:35:54 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YZPBG-0005ak-9N for pgsql-hackers@postgresql.org; Sat, 21 Mar 2015 19:35:34 +0000 Received: from jiboia.ensmp.fr ([194.214.158.103]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YZPB9-0006MF-A8 for pgsql-hackers@postgresql.org; Sat, 21 Mar 2015 19:35:29 +0000 Received: from cri.ensmp.fr (154.237.219.88.rev.sfr.net [88.219.237.154]) (authenticated bits=0) by jiboia.ensmp.fr (8.14.9/8.14.9/JMMC-22/Oct/2013) with ESMTP id t2LJZKkX010147 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 21 Mar 2015 20:35:21 +0100 Date: Sat, 21 Mar 2015 20:35:18 +0100 (CET) From: Fabien COELHO X-X-Sender: fabien@sto To: Andres Freund cc: Tomas Vondra , Robert Haas , PostgreSQL Developers Subject: Re: PATCH: pgbench - merging transaction logs In-Reply-To: <20150321095006.GA3075@awork2.anarazel.de> Message-ID: References: <54FCB11B.5050907@2ndquadrant.com> <5505CF30.7030308@2ndquadrant.com> <550CCBE5.8060009@2ndquadrant.com> <20150321095006.GA3075@awork2.anarazel.de> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Miltered: at jiboia.ensmp.fr with ID 550DC7F8.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: 550DC7F8.000 from 154.237.219.88.rev.sfr.net/154.237.219.88.rev.sfr.net/88.219.237.154/cri.ensmp.fr/ X-Pg-Spam-Score: -1.9 (-) Content-Type: TEXT/PLAIN; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8BIT 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 Hello Andres, >> With your worst-case figure and some rounding, it seems to look like: >> >> #threads collision probability performance impact >> 2 1/40 1/3200 >> 4 1/7 1/533 >> 8 0.7 < 0.01 (about 1%) >> >> This suggest that for a pessimistic (ro load) fprintf overhead ratio there >> would be a small impact even with 8 thread doing 20000 tps each. > > I think math like this mostly disregards hardware realities. Hmmm. In my mind, doing the maths helps understand what may be going on. Note that it does not preclude to check afterwards that it does indeed correspond to reality:-) The key suggestion of the maths is that if p*t << 1 all is (seems) well. > You don't actually need to have actual lock contention to notice > overhead. The overhead assumed is 1/40 of the transaction time from Tomas' measures. Given the ~ 18000 tps (we are talking of an in-memory read-only load probably on the same host), transaction time for pgbench seems to be about 0.06 ms, and fprintf seems to be about 0.0015 ms (1.5 µs). > - frequently acquiring an *uncontended* lock that resides in another > socket's cache and where the cacheline is dirty requires relatively > expensive cross cpu transfers. That's all besides the overhead of doing > a lock operation itself. A lock; xaddl;, or whatever you end up using, > has a significant cost in itself. It implies a bus lock and cache flush, > which is far from free. Ok, I did not assume an additional "lock cost". Do you have a figure? A quick googling suggested figure for "lightweight mutexes" around 100 ns, but the test conditions were unclear. If it is oky, then it is does not change much the above maths to add that overhead. > Additionally we're quite possibly talking about more than 8 threads. > I've frequently used pgbench with hundreds of threads; for imo good > reasons. Good for you. I do not have access to a host on which this would make sense:-) > That all said, it's far from guaranteed that there's an actual problem > here. If done right, i.e. the expensive formatting of the string is > separated from the locked output to the kernel, it might end up being > acceptable. That is what I would like to assess. Indeed, probably snprinf (to avoid mallocing anything) and then fputs/write/whatever would indeed help reduce the "contention" probability, if not the actual overhead. -- Fabien. -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers