Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZCdvE-0001PQ-Nx for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jul 2015 01:13:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZCdvE-0000UW-2e for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jul 2015 01:13:12 +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 1ZCdvD-0000UP-3r for pgsql-bugs@postgresql.org; Wed, 08 Jul 2015 01:13:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZCdv9-0007rL-Fm for pgsql-bugs@postgresql.org; Wed, 08 Jul 2015 01:13:10 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t681D4vV031266; Tue, 7 Jul 2015 21:13:05 -0400 From: Tom Lane To: grb@skogoglandskap.no cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13493: pl/pgsql doesn't scale with cpus (PG9.3, 9.4) In-reply-to: <20150707222739.1188.8068@wrigleys.postgresql.org> References: <20150707222739.1188.8068@wrigleys.postgresql.org> Comments: In-reply-to grb@skogoglandskap.no message dated "Tue, 07 Jul 2015 22:27:39 -0000" Date: Tue, 07 Jul 2015 21:13:04 -0400 Message-ID: <31265.1436317984@sss.pgh.pa.us> 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 grb@skogoglandskap.no writes: > pl/pgsql doesn't scale properly on postgres 9.3/9.4 with multiple processors > beyond 2-3 processors for me, regardless of the machine I use or the > benchmark/project. > The benchmark results & source code are here: > https://github.com/gbb/ppppt First off, thanks for providing a concrete test case! It's always a lot easier to investigate when a problem can be reproduced locally. Having said that ... 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. 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. 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. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs