Re: Hmmm... why does CPU-intensive pl/pgsql code parallelise so badly when queries parallelise fine? Anyone else seen this?

From: "Graeme B(dot) Bell" <graeme(dot)bell(at)nibio(dot)no>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: Craig James <cjames(at)emolecules(dot)com>, "Graeme B(dot) Bell" <graeme(dot)bell(at)nibio(dot)no>, postgres performance list <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Hmmm... why does CPU-intensive pl/pgsql code parallelise so badly when queries parallelise fine? Anyone else seen this?
Date: 2015-07-08 11:06:50
Message-ID: 8B7F17BD-2E78-4684-B930-CB4E635B5B76@skogoglandskap.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> On 07/07/2015 08:05 PM, Craig James wrote:
>>
>>
>> No ideas, but I ran into the same thing. I have a set of C/C++ functions
>> that put some chemistry calculations into Postgres as extensions (things
>> like, "calculate the molecular weight of this molecule"). As SQL
>> functions, the whole thing bogged down, and we never got the scalability
>> we needed. On our 8-CPU setup, we couldn't get more than 2 CPUs busy at
>> the same time, even with dozens of clients.

Hi all,

The sample code / results were put up last night at http://github.com/gbb/ppppt

Craig's problem sounds similar to my own, assuming he means running C indirectly via SQL vs running C more directly.
Lots of parallel connections to postgres but maximum 2 CPUs of scaling (and it gets worse, as you try to run more things).

Tom Lane has posted an interesting comment over on the bugs list which identies a likely source at least one of the problems, maybe both.
It seems to be linked to internal locking inside postgres (which makes sense, given the results - both problems feel 'lock-y').
Also, he mentions a workaround for some functions that scales to 8-way apparently.

http://www.postgresql.org/message-id/31265.1436317984@sss.pgh.pa.us

I think it's potentially a big problem for CPU intensive postgres libraries like pgrouting, or perhaps the postgis & postgis raster functions, things like that.
I don't know how well their functions are marked for e.g. immutability.
Are there any postgis devs on this list?

Graeme Bell

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Graeme B. Bell 2015-07-08 11:13:04 Re: Hmmm... why does pl/pgsql code parallelise so badly when queries parallelise fine? Anyone else seen this?
Previous Message Marc Mamin 2015-07-08 07:43:54 Re: wildcard text filter switched to boolean column, performance is way worse