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 1jppus-0002ZT-IJ for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2020 09:17:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jppur-000155-Bw for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2020 09:17: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 1jppur-00014y-2V for pgsql-hackers@lists.postgresql.org; Mon, 29 Jun 2020 09:17:29 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jppuo-0002Z1-W5 for pgsql-hackers@postgresql.org; Mon, 29 Jun 2020 09:17:28 +0000 Received: by mail-qt1-x841.google.com with SMTP id g13so12278256qtv.8 for ; Mon, 29 Jun 2020 02:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=x1X02Bl6LHIEVlBnzvwH7F4g3ekAUcOYkebzEkb3F2A=; b=XqvTU2QMkOaGVEgbvKU4vBI8Bm/yppFnnfLrHrHLSVQzJFF0kbIzLbAnFyq7gU4iCF 2BctdYPf5whX+BYZghEJAYpi33nrgBmaRayoPGXh8SKAL+RawJyDOp7Sv87JLUX5cwpZ qXwvyZSl050qf1vo8tx49hubftVxvk4MGB1TDe3sFk57D/eg2Zx6jQ2DulPyn1fVStqY V8c/H8ptmNyOI1EQ0+p3JzqOzBoUCX06l/jYyH/y+yI8OFnUm+b/Mkfa0ATzjAQGzjRG GCoJksinh0a/ewM+5bOhdrH627BvBlNEwPswOrmJn0qp8PIDHXb+/BfxpRTqWMqYaaBN e2BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=x1X02Bl6LHIEVlBnzvwH7F4g3ekAUcOYkebzEkb3F2A=; b=ReD7fMoRqkE8vykTzmtTY7iyRGCHp12XUHYqrepziY1AZQ+kMgXcGT7K9Ghv3J32Y2 5/WnIe7gg9w6jlZq6YBqdVT3kTeoY7uEcn32RE5hexUg5iN2CgIOrpjjImbXqHX7xXNy CN5dWC1FtC0QK7oR0ADgvo5JPFO6BLXiaJyP+LbMBqUODLr6VdmfFcelxxPUauyWvgpP qdqe6sZiEa+0O3jQOP+FYfXIyhF76nB+zlOOULE7NZ0tRucFtiUIGyFbJ2dE3yhNgxQ8 3LtdI/hHcMAYhzfaHzINwFCpINI4b5l8vN6uwqzPRXKH6o6PiEd4KK6Y8UoDjWz99va3 aDUg== X-Gm-Message-State: AOAM533yy6u80nRwLd73w5X34/Sxy857mXtZzwFUWlOZfGYS9wwhf/Zo bV20+ij+KC/3WhxoZUJ/Yh6hGrlW3g7IDXrWtfI= X-Google-Smtp-Source: ABdhPJzMPmQc5cDP1XNtBYmXJtm+v92EfvPHUCdovMg55/EchvoPFckFINOx2JUyLyB8yRRMES+KbJ6JYtfe90RwPO4= X-Received: by 2002:ac8:3528:: with SMTP id y37mr14623662qtb.308.1593422245317; Mon, 29 Jun 2020 02:17:25 -0700 (PDT) MIME-Version: 1.0 References: <2895b53b033c47ccb22972b589050dd9@EX13D05UWC001.ant.amazon.com> In-Reply-To: From: Julien Rouhaud Date: Mon, 29 Jun 2020 11:17:14 +0200 Message-ID: Subject: Re: track_planning causing performance regression To: Fujii Masao Cc: "Tharakan, Robins" , "pgsql-hackers@postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Jun 29, 2020 at 10:55 AM Fujii Masao wrote: > > On 2020/06/29 16:05, Julien Rouhaud wrote: > > On Mon, Jun 29, 2020 at 7:49 AM Tharakan, Robins wrote: > >> > >> During fully-cached SELECT-only test using pgbench, Postgres v13Beta1 shows > > Thanks for the benchmark! > > > >> ~45% performance drop [2] at high DB connection counts (when compared with v12.3) > > That's bad :( > > > >> > >> Disabling pg_stat_statements.track_planning (which is 'On' by default) > >> brings the TPS numbers up to v12.3 levels. > >> > >> The inflection point (in this test-case) is 128 Connections, beyond which the > >> TPS numbers are consistently low. Looking at the mailing list [1], this issue > >> didn't surface earlier possibly since the regression is trivial at low connection counts. > >> > >> It would be great if this could be optimized further, or track_planning > >> disabled (by default) so as to not trip users upgrading from v12 with pg_stat_statement > >> enabled (but otherwise not particularly interested in track_planning). > > Your benchmark result seems to suggest that the cause of the problem is > the contention of per-query spinlock in pgss_store(). Right? > This lock contention is likely to happen when multiple sessions run > the same queries. > > One idea to reduce that lock contention is to separate per-query spinlock > into two; one is for planning, and the other is for execution. pgss_store() > determines which lock to use based on the given "kind" argument. > To make this idea work, also every pgss counters like shared_blks_hit > need to be separated into two, i.e., for planning and execution. This can probably remove some overhead, but won't it eventually hit the same issue when multiple connections try to plan the same query, given the number of different queries and very low execution runtime? It'll also quite increase the shared memory consumption. I'm wondering if we could instead use atomics to store the counters. The only downside is that we won't guarantee per-row consistency anymore, which may be problematic.