Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2Ht4-0005To-24 for pgsql-performance@arkaria.postgresql.org; Wed, 11 Oct 2017 14:21:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e2Ht3-0002Uo-I1 for pgsql-performance@arkaria.postgresql.org; Wed, 11 Oct 2017 14:21:29 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e2Ht3-0002UT-0Q for pgsql-performance@postgresql.org; Wed, 11 Oct 2017 14:21:29 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1e2Hsu-0007nZ-L7 for pgsql-performance@postgresql.org; Wed, 11 Oct 2017 14:21:27 +0000 Received: by mail-wm0-x231.google.com with SMTP id i124so5291823wmf.3 for ; Wed, 11 Oct 2017 07:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=jmiCaiczRfiuTBxjXzX7zl6VulJoJhcxUXRXl6vN0II=; b=DTo36xNA85AJ377n0uNM3o/I5WGQOWK4j8Ni/5QCOspFLsHWE9COEXwZrF+5dGgm1d ALZMq2qHgbrIUelVQtiyy+UnmuBbyn0k17vy85TlQYkaFYcm49BWrQHLZ2iPUj2Z9svw r+XrDWMMaViBUNJZbOgFDNawJjxn1g/KWQr2NOSE4H40CPMOHtpW3F6v+iwWzPHAmZmX J89RS7NoU2CfEvow1kcBFv1GPjtZfefFNx9qoQX5hn3nf9b/lbvK9ivcFbG2OE/IopWG i4hqkn8CHAQxNEoXN7zMlgR33+Jn9PhxBYaujgGC0Qk9rw5knhcS3UPTLti7F1RNti2R HndQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=jmiCaiczRfiuTBxjXzX7zl6VulJoJhcxUXRXl6vN0II=; b=b3NsnpXgZJpFEwzhN8fQNjBI4O7kfkIP48ECvsfYYSSymMicGDHhu6O0SDwR7WG0Vw G/BVk3MMKgElfs7Cg+A700fKkWnhfkndmZGPWcxkjCszZd6xNMAdy3v7ElXQWKnbzLhQ sq6CkKiPyERNJqEwzuZKDpPl5wKlkKan55OJPq+SNZesEhrgHHqCcZF7RPpyy3aeC6gl 60TtPP1+DLpsFo2gNaYPQB8YI8lfwAn70l/0O9ZDONbMSI82rmV/BMRyuTjWB6l4IE2h 1p3Ad8tSPSleysf+rU+LcEjZstYo0nFRoVWAKqObuEbFtkmIPOOvlMk9+le5A5nGZKrk 8uGg== X-Gm-Message-State: AMCzsaVl8n4rkjTQqnqcxJ6iobLEBVGnUfHb6Kj4IN/cxmRhb21IHMfF MPd307hXnTmd2vTfTHesELhHb3whVgL9UkiJFfs= X-Google-Smtp-Source: AOwi7QC+QZ7KtTxieoCar3FHV7sjhTuBoJS5MubEQr60FKwnPSX/bCoOz0JRafiNLkMnoWgwhIklhYfl3CSxN0RyqNs= X-Received: by 10.28.48.150 with SMTP id w144mr10240867wmw.23.1507731677292; Wed, 11 Oct 2017 07:21:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.146.7 with HTTP; Wed, 11 Oct 2017 07:20:36 -0700 (PDT) In-Reply-To: References: <1507042486.2998.1.camel@cybertec.at> From: Pavel Stehule Date: Wed, 11 Oct 2017 16:20:36 +0200 Message-ID: Subject: Re: Stored Procedure Performance To: Purav Chovatia Cc: Laurenz Albe , "pgsql-performance@postgresql.org" Content-Type: multipart/alternative; boundary="001a1142427e0ab083055b462392" 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 --001a1142427e0ab083055b462392 Content-Type: text/plain; charset="UTF-8" 2017-10-11 15:59 GMT+02:00 Purav Chovatia : > Thanks Laurenz, am having a look at perf. > > Can you pls help understand what exactly do you mean when you say "PL/pgSQL > is not optimized for performance like PL/SQL". Do you mean to indicate that > app firing queries/DMLs directly would be a better option as compared to > putting those in Stored Procs? > PL/pgSQL is perfect glue for SQL. SQL queries has same speed without dependency on environment that executed it. This sentence mean, so PLpgSQL is not designed for intensive mathematics calculation. PL/SQL is self govering environment ... it has own data types, it has own implementation of logical and mathematics operators. PLpgSQL is layer over SQL engine - and has not own types, has not own operators. Any expression is translated to SQL and then is interpreted by SQL expression interpret. Maybe in next few years there will be a JIT compiler. But it is not now. This is current bottleneck of PLpgSQL. If your PL code is glue for SQL queries (implementation of some business processes), then PLpgSQL is fast enough. If you try to calculate numeric integration or derivation of some functions, then PLpgSQL is slow. It is not too slow - the speed is comparable with PHP, but it is significantly slower than C language. PostgreSQL has perfect C API - so intensive numeric calculations are usually implemented as C extension. Regards Pavel > > Regards > > On 3 October 2017 at 20:24, Laurenz Albe wrote: > >> Purav Chovatia wrote: >> > I come from Oracle world and we are porting all our applications to >> postgresql. >> > >> > The application calls 2 stored procs, >> > - first one does a few selects and then an insert >> > - second one does an update >> > >> > The main table on which the insert and the update happens is truncated >> before every performance test. >> > >> > We are doing about 100 executions of both of these stored proc per >> second. >> > >> > In Oracle each exec takes about 1millisec whereas in postgres its >> taking 10millisec and that eventually leads to a queue build up in our >> application. >> > >> > All indices are in place. The select, insert & update are all single >> row operations and use the PK. >> > >> > It does not look like any query taking longer but something else. How >> can I check where is the time being spent? There are no IO waits, so its >> all on the CPU. >> >> You could profile the PostgreSQL server while it is executing the >> workload, >> see for example https://wiki.postgresql.org/wiki/Profiling_with_perf >> >> That way you could see where the time is spent. >> >> PL/pgSQL is not optimized for performance like PL/SQL. >> >> Yours, >> Laurenz Albe >> > > --001a1142427e0ab083055b462392 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


2017-10-11 15:59 GMT+02:00 Purav Chovatia <puravc@gmail.com>:
Thanks Laurenz, am = having a look at perf.

Can you pls help understand what = exactly do you mean when you say "PL/= pgSQL is not optimized for performance like PL/SQL". Do you mean to in= dicate that app firing queries/DMLs directly would be a better option as co= mpared to putting those in Stored Procs?

PL/pgSQL is perfect glue for SQL. SQL queries has same spe= ed without dependency on environment that executed it.

=
This sentence mean, so PLpgSQL is not designed for intensive mathemati= cs calculation.=C2=A0 PL/SQL is self govering environment ... it has own da= ta types, it has own implementation of logical and mathematics operators. P= LpgSQL is layer over SQL engine - and has not own types, has not own operat= ors. Any expression is translated to SQL and then is interpreted by SQL exp= ression interpret. Maybe in next few years there will be a JIT compiler. Bu= t it is not now. This is current bottleneck of PLpgSQL. If your PL code is = glue for SQL queries (implementation of some business processes), then PLpg= SQL is fast enough. If you try to calculate numeric integration or derivati= on of some functions, then PLpgSQL is slow. It is not too slow - the speed = is comparable with PHP, but it is significantly slower than C language.

PostgreSQL has perfect C API - so intensive numeric c= alculations are usually implemented as C extension.

Regards

Pavel
=C2=A0

Regards

On 3 October 2017 at 20:24, Laurenz Albe <laurenz.albe@cybertec.at> wrote:
Purav Chovatia wrote:
> I come from Oracle world and we are porting all our applications to po= stgresql.
>
> The application calls 2 stored procs,=C2=A0
> - first one does a few selects and then an insert
> - second one does an update
>
> The main table on which the insert and the update happens is truncated= before every performance test.
>
> We are doing about 100 executions of both of these stored proc per sec= ond.
>
> In Oracle each exec takes about 1millisec whereas in postgres its taki= ng 10millisec and that eventually leads to a queue build up in our applicat= ion.
>
> All indices are in place. The select, insert & update are all sing= le row operations and use the PK.
>
> It does not look like any query taking longer but something else. How = can I check where is the time being spent? There are no IO waits, so its al= l on the CPU.

You could profile the PostgreSQL server while it is executing the
workload,
see for example https://wiki.postgresql.org/wiki/Profiling_with_perf

That way you could see where the time is spent.

PL/pgSQL is not optimized for performance like PL/SQL.

Yours,
Laurenz Albe


--001a1142427e0ab083055b462392--