Re: Utilizing multiple cores in a function call. - Mailing list pgsql-performance

From Greg Smith
Subject Re: Utilizing multiple cores in a function call.
Date
Msg-id alpine.GSO.2.01.0906291429000.28239@westnet.com
Whole thread Raw
In response to Utilizing multiple cores in a function call.  ("Hartman, Matthew" <Matthew.Hartman@krcc.on.ca>)
Responses Re: Utilizing multiple cores in a function call.  (Craig Ringer <craig@postnewspapers.com.au>)
List pgsql-performance
On Mon, 29 Jun 2009, Hartman, Matthew wrote:

> The function throttles one of my CPUs to 100% (shown as 50% in Task
> Manager) and leaves the other one sitting pretty. Is there any way to
> use both CPUs?

Not easily.  Potential techniques:

-Rewrite the function or its time critical portion in some other language
that allows using two processes usefully

-Write a "worker server" that you prompt to pick up work from a table and
write its output to another that you can ask to handle part of the job.
You might communicate with the worker using the LISTEN/NOTIFY mechanism in
the database.

-Some combination of these two techniques.  One popular way to speed up
things that are running slowly is to run some part of them in a C UDF, so
that you could use "select my_big_computation(x,y,z)" and get faster
execution.

If you were hoping for a quick answer, no such thing.  I suspect you'd get
better help talking about what your function does and see if there's a
specific part somebody else is familiar with optimizing.

For example, I've seen >10:1 speedups just be rewriting one small portion
of a computationally expensive mathematical function in C before, keeping
the rest of the logic on the database side.  You don't necessarily have to
rewrite the whole thing.

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

pgsql-performance by date:

Previous
From: Joe Conway
Date:
Subject: Re: Utilizing multiple cores in a function call.
Next
From: Merlin Moncure
Date:
Subject: Re: Utilizing multiple cores in a function call.