Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZCeTh-00032w-Mj for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jul 2015 01:48:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZCeTg-0000S9-Rn for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jul 2015 01:48:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZCeSs-0008Cs-EG for pgsql-bugs@postgresql.org; Wed, 08 Jul 2015 01:47:58 +0000 Received: from mail-la0-x22c.google.com ([2a00:1450:4010:c03::22c]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZCeSk-000050-Ak for pgsql-bugs@postgresql.org; Wed, 08 Jul 2015 01:47:57 +0000 Received: by lagx9 with SMTP id x9so215507045lag.1 for ; Tue, 07 Jul 2015 18:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=RQvPEbZxWnRbDX9czU/uSj5LRfghCo1KHFFMcYMyfhw=; b=lwDM0jErC5G3tMVFIyz19uI5EqmeY3ek2Ri+BEwBegcMXbVV5z4fD8vamdkTN70ov2 8jKe7T4b+5jzKars6ojja4ioC1z+oWHDzDonHya9Xk3S/+Cg2t0mVLeodoAIvvWcCsnq Ci+sS0+HAuprTSYy8zROL6T5M9OvjRnHQGLX2fUqsRHkVnjBq/2jS8CQICmzE5un7pJw HrWtUHOQknrpqiM+5sK0JXHgkxUOinsZ/xAd0aWtpf5/zDHsUUFoWPeJ68PeGwE/3V48 AQrhlWkKnP0EKIB1ZCkmQyZZGvSXsXE43siyuNyak2SzJEPeCCxup20DqTj+iHcSGD4Z x4vg== X-Received: by 10.112.55.207 with SMTP id u15mr6691882lbp.88.1436320069166; Tue, 07 Jul 2015 18:47:49 -0700 (PDT) Received: from [192.168.0.101] (ti0056a400-6081.bb.online.no. [85.165.98.212]) by smtp.gmail.com with ESMTPSA id q1sm43590lah.27.2015.07.07.18.47.47 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Jul 2015 18:47:48 -0700 (PDT) Subject: Re: BUG #13493: pl/pgsql doesn't scale with cpus (PG9.3, 9.4) Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Content-Type: text/plain; charset=us-ascii From: Graeme In-Reply-To: <31265.1436317984@sss.pgh.pa.us> Date: Wed, 8 Jul 2015 03:47:46 +0200 Cc: grb@skogoglandskap.no, pgsql-bugs@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <681C25CA-EC03-4849-B88C-3C7C804A52A8@gmail.com> References: <20150707222739.1188.8068@wrigleys.postgresql.org> <31265.1436317984@sss.pgh.pa.us> To: Tom Lane X-Mailer: Apple Mail (2.2098) X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org > On 8 Jul 2015, at 03:13, Tom Lane wrote: >=20 > grb@skogoglandskap.no writes: >> pl/pgsql doesn't scale properly on postgres 9.3/9.4 with multiple proces= sors >> beyond 2-3 processors for me, regardless of the machine I use or the >> benchmark/project.=20 >=20 >> The benchmark results & source code are here: >> https://github.com/gbb/ppppt >=20 > First off, thanks for providing a concrete test case! It's always a lot > easier to investigate when a problem can be reproduced locally. >=20 > Having said that ... >=20 > plpgsql is really designed as a glue language for SQL queries, not for > heavy-duty computation, so these examples aren't exactly showing it at > its best. It would be worth your while to consider using some other > convenient programming language, perhaps plperl or plpython or plv8, > if you want to do self-contained calculations on the server side. I'm very interested in trying out plv8, but it is a problem for projects wh= en you have a team of people who know plpgsql and a lot of plpgsql legacy c= ode. It would be interesting to know what happens when these functions are porte= d into those other languages.=20 > But I think that the main problem you are seeing here is from snapshot > acquisition contention. By default, plpgsql acquires a new snapshot > for each statement inside a function, and that results in a lot of > contention for the ProcArray if you're maxing out a multicore machine. > Depending on what you're actually doing inside the function, you might > well be able to mark it stable or even immutable, which would suppress > the per-statement snapshot acquisitions. On my machine (admittedly only > 8 cores), the scalability problems in this example pretty much vanish > when I attach "stable" to the function definitions. Thanks for testing it on your own machine and looking into a possible cause. Do you think that explains both problems (one occurs with table data; one o= ccurs with work)? Several of the functions that were killing me last year were dynamic SQL wi= th some internal state, so declaring them harmless and predictable probably= isn't possible. I will need to go back and check.=20 It sounds like marking up functions may help (at least as far as 8 cores), = but there must be a lot of people out there running plpgsql they have porte= d over from oracle, (postgis? pgrouting? not sure about their internals) et= c, and various libraries where the functions aren't marked up and can't eas= ily be marked up. A broader solution in the far off future would be awesome= , if it is ever possible. I am not in a position currently to provide it, I= regret.=20 > There is some discussion going on about improving the scalability of > snapshot acquisition, but nothing will happen in that line before 9.6 > at the earliest. Thanks, this is interesting to know. Thanks again for your time looking into this and for the stable/immutable t= ip. Graeme. >=20 > regards, tom lane >=20 >=20 > --=20 > Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-bugs --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs