Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZChzo-0007zH-1s for pgsql-performance@arkaria.postgresql.org; Wed, 08 Jul 2015 05:34:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZChzn-0001QN-6p for pgsql-performance@arkaria.postgresql.org; Wed, 08 Jul 2015 05:34:11 +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 1ZChxZ-0007RN-2k for pgsql-performance@postgresql.org; Wed, 08 Jul 2015 05:31:53 +0000 Received: from lists.commandprompt.com ([69.168.55.30]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZChxU-0004Jj-G7 for pgsql-performance@postgresql.org; Wed, 08 Jul 2015 05:31:51 +0000 Received: from [192.168.1.3] (spinlock.commandprompt.com [69.168.55.30]) by lists.commandprompt.com (Postfix) with ESMTPA id A71D4222; Tue, 7 Jul 2015 22:31:45 -0700 (PDT) Received: from [192.168.1.3] ([67.168.169.165] helo=[192.168.1.3]) by assp.commandprompt.com with ESMTPS(AES128-SHA) (2.1.1); 7 Jul 2015 22:31:44 -0700 Message-ID: <559CB5BF.2080509@commandprompt.com> Date: Tue, 07 Jul 2015 22:31:43 -0700 From: "Joshua D. Drake" Organization: Command Prompt, Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Craig James , "Graeme B. Bell" CC: postgres performance list Subject: Re: Hmmm... why does CPU-intensive pl/pgsql code parallelise so badly when queries parallelise fine? Anyone else seen this? References: <6E55113B-FA05-433C-9B21-623F798EE935@skogoglandskap.no> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Assp-Version: 2.1.1(11364) on assp.commandprompt.com X-Assp-Client-SSL: yes X-Assp-ID: assp.commandprompt.com m1-33505-12541 X-Assp-Envelope-From: jd@commandprompt.com X-Assp-Intended-For: pgsql-performance@postgresql.org X-Assp-Original-Subject: Re: [PERFORM] Hmmm... why does CPU-intensive pl/pgsql code paralleliseso badly when queries parallelise fine? Anyone else seen this? X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org 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. > > When I moved these same functions into an Apache fast-CGI HTTP service > (exact same code, same network overhead), I could easily scale up and > use the full 100% of all eight CPUs. > > I have no idea why, and never investigated further. The convenience of > having the functions in SQL wasn't that important. I admit that I haven't read this whole thread but: Using Apache Fast-CGI, you are going to fork a process for each instance of the function being executed and that in turn will use all CPUs up to the max available resource. With PostgreSQL, that isn't going to happen unless you are running (at least) 8 functions across 8 connections. JD -- Command Prompt, Inc. - http://www.commandprompt.com/ 503-667-4564 PostgreSQL Centered full stack support, consulting and development. Announcing "I'm offended" is basically telling the world you can't control your own emotions, so everyone else should do it for you. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance