Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kFbBr-0005xG-3s for pgsql-performance@arkaria.postgresql.org; Tue, 08 Sep 2020 10:49:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kFbBp-0003iU-Et for pgsql-performance@arkaria.postgresql.org; Tue, 08 Sep 2020 10:49:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kFbBp-0003iN-3E for pgsql-performance@lists.postgresql.org; Tue, 08 Sep 2020 10:49:29 +0000 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kFbBm-00060y-B1 for pgsql-performance@lists.postgresql.org; Tue, 08 Sep 2020 10:49:28 +0000 Received: by mail-il1-x129.google.com with SMTP id m1so14894762ilj.10 for ; Tue, 08 Sep 2020 03:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=WpO4sILq7MfxLBVxjvKZVu0i0CGH8po9Wwg3szf380g=; b=YpCgw5X+0283Y4W1NMqig6osSW7STLiqwzLEadY5W4MOJr6r41KBCtZNUcUpJLIckR NcXn+cajw8ThjwyePOgguFoBRoZpNyNPb4Ieu3Vw99VBAj3QlNefTAuV3lDYuiXR2Nsl 9B8gVgOmtQJHfOMwiIYO5e6UxxdCLkfLG8rGnmWF/MnKEofPMaStOnN3PHJ9Yr/+WPtt hwdtt96+qNjP0Ea75uLuiJQbgkZGxc5tf+Lvak/X0NBIug4yvJPKvxuZ01iFtt8b+e9J C6Yc3sabdQspR0tdw0l6uoZSQ1PTrjMyF0xjhGX06nyqJ0flt6fBi/J2JL0JqX6Cuzua asmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=WpO4sILq7MfxLBVxjvKZVu0i0CGH8po9Wwg3szf380g=; b=B//fAImymA1lNH56YU/c+DOB/jA3CoQ5iWR3hdoKc63b7Sfmv2eDQUIAWL/50283Xu C4m9ywq63PLxin9+Qc2yzYMSwvXtJN+jzLV80EJKiiad1ikyICCIkTlyH68Xknrs5Plk 5Qe5yk/yAaJlonfZhf2/Ou2/dsfakgBLhswQ3jllVn+TquHUwYbkI9d7ccet71/z4wDA z2QCEcErBbRRTFznMwVQzrHMxIFTQ/PbWM8D7gx4mINb+jGKag7joH6PQAJqrb04T0Vm nE3BU9wPImVGMHGSpHnoBPgDdJi0MbabRsiRW0sARoijN+yikig/Khpr4qKGHEM/Thqg IzFA== X-Gm-Message-State: AOAM5323ufYtuM05EzJ6TAUAM+6yShIdH749hdDFkfBZmqw4sYGeUBea +QuLzDQ8ya8IY3ZfsfCEZOSIv8roeA3Hug== X-Google-Smtp-Source: ABdhPJxgZnTAf/wDu49X7/7ozDrLX5q2SBSL5pdk7U3TMhEp4XpNLw+S+AwvM3UeXqPVcQgm82qMiQ== X-Received: by 2002:a92:60b:: with SMTP id x11mr21524609ilg.179.1599562163956; Tue, 08 Sep 2020 03:49:23 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id l2sm9761202ilk.19.2020.09.08.03.49.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Sep 2020 03:49:23 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 35AC580063E; Tue, 8 Sep 2020 05:49:22 -0500 (CDT) Date: Tue, 8 Sep 2020 05:49:22 -0500 From: Justin Pryzby To: Dirk Krautschick Cc: pgsql-performance@lists.postgresql.org Subject: Re: Query Performance in bundled requests Message-ID: <20200908104922.GA15392@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Sep 08, 2020 at 10:30:50AM +0000, Dirk Krautschick wrote: > Update: Better title and format corrections > > Hi %, > > in order to be able to readjust the effects of the stored procedure and, if necessary, to save turnaround times, different requests can be concatenated using semicolons for bundling several statements in one request. We did some tests against a postgres cluster. > > The results in terms of optimizations are as follows: > > > Batchsize | clients| count Queries | average s/query| comment > --------------|---------|----------------------|----------------------|- > 1 | 1 | 15.86k | 2.24ms | > 10 | 1 | 31.80k | 332us | > 25 | 1 | 31.75k | 312us | > 50 | 1 | 32.00k | 280us | I guess you're looking at the minimum of 280us. ; 1/(280e-6) * 60 ~214285.71428571428571428571 > the question remains why this is so. You can't expect it to go a billion times faster just by putting a billion queries in one request, and at 50 batches it looks like you've hit the next performance bottleneck. Whether that's CPU / IO / network / locks / RAM / planner / context switches / logging / ??? remains to be seen. > Does anyone has experience with something similar or are there some > hints about how to optimize the postgres cluster for such bundled statements? I think at this step you want to optimize for what the statements are doing, not for the statements themselves. Could you send a query plan for the stored procedure ? Also, you'd maybe want to think if there's a way you can avoid making 100s of 1000s of requests per second, rather than trying to optimize for it. Can you make another stored procedure which handles N requests rather than calling this SP N times ? There's no guarantee that won't hit the same or other bottleneck, until you see what that is. -- Justin