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 1jgsw4-0005ik-EK for pgsql-performance@arkaria.postgresql.org; Thu, 04 Jun 2020 16:41:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jgsw3-0002YU-2x for pgsql-performance@arkaria.postgresql.org; Thu, 04 Jun 2020 16:41:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgsw2-0002YN-Me for pgsql-performance@lists.postgresql.org; Thu, 04 Jun 2020 16:41:42 +0000 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jgsvy-0001oz-U3 for pgsql-performance@lists.postgresql.org; Thu, 04 Jun 2020 16:41:41 +0000 Received: by mail-qk1-x729.google.com with SMTP id c185so6682537qke.7 for ; Thu, 04 Jun 2020 09:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=americanefficient-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tXvn+eYoyKhU00fqy38xCd+wgRTnQjiUNjob3R5fXKM=; b=1+LkAMJKMNLyVEHvukuABA43kzfuWgVEjz5jEnCzLM/6v4VvZoQSSFsEFaB8WBiXMs amSfhdWJCompWEE1/hhzbQ+0JQE4I1K3YzzEVqGwE2cnqN7Sm1MmQJcFfNeuabTlFXws 04RtrQjaYGo2URK88I80Zj8hqOth4fSOGj/rKyUdfb1J7/dZkTXJ16XxdHYB+nlrUnML rJrkUwETGrg7JWe7JbABKOHTkyQUwkf1F7so8lWn9h5C8MPStfxhzSv0RT1MlHTzNLk+ sWIVwd7y8pTwZHysXwd4Wfgf6oO4ikMpwxYxuWwZGL+E0xWKaIwuxwkWZR5uIrZ3BjQO cVBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tXvn+eYoyKhU00fqy38xCd+wgRTnQjiUNjob3R5fXKM=; b=uTFqZ5q47I3khJ2Rr3mWz2ppvI5jspXFCDKqCHimOgg9lpQygQcdpK2uWh2juGVG/5 sl4O8IBrOcWu8WFi9XZCtJzfjU2tz4R9X0zyf9mW6geQwR2PybJdVnl5LrPTd18/8vVe 2hcDEv/yG/H6QeCz574UHeAGM1Xz+u7hjdq4cAkMDDxZaUm5memSBVgRb8bu6shMIf8S KRnFURUy2ty79lGdby29iTqjGan7OGIdbwVN+lrqewbOh+HKPL+Zg/m/wohWyasKHOz8 0/ST7yVJlX2Kj77JA9ED0Yh4EvVEYJG4+7tjEuk2jwbU5R5tjb+uPwqnMhPRN1/ZoNlI 2mIA== X-Gm-Message-State: AOAM532+/THsRm6fCcY+H+Yg8C9sOzKk5K/gV8Q8OgYh9IGdUDKTidX1 33rn4HHOFFZ9VnJzYrKmi2z6Zg== X-Google-Smtp-Source: ABdhPJyoW3wqhiadCNFImt4yaqL/eIF6WLWOQfgDfsGNM01f7+aTR3PGXhAjHbctj8ed/MpF2bncfQ== X-Received: by 2002:a37:b9c7:: with SMTP id j190mr5356060qkf.210.1591288897334; Thu, 04 Jun 2020 09:41:37 -0700 (PDT) Received: from [10.0.1.5] (user-10lff1p.cable.mindspring.com. [65.87.188.57]) by smtp.gmail.com with ESMTPSA id v53sm5713805qtv.10.2020.06.04.09.41.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jun 2020 09:41:36 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: increased max_parallel_workers_per_gather results in fewer workers? From: Philip Semanchuk In-Reply-To: <4384167D-196A-4630-A683-B229177F8AFD@swarm64.com> Date: Thu, 4 Jun 2020 12:41:35 -0400 Cc: "pgsql-performance@lists.postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <89423FD3-0F13-447D-8D9E-EB1722150F94@americanefficient.com> References: <20200603211526.GU30144@telsasoft.com> <1F407302-1203-41DB-9A9C-69EA0FAFDCC6@americanefficient.com> <4384167D-196A-4630-A683-B229177F8AFD@swarm64.com> To: Sebastian Dressler X-Mailer: Apple Mail (2.3608.80.23.2.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Jun 4, 2020, at 2:28 AM, Sebastian Dressler = wrote: >=20 > Hi Philip, >=20 >> On 4. Jun 2020, at 00:23, Philip Semanchuk = wrote: >>=20 >>> I guess you should show an explain analyze, specifically "Workers >>> Planned/Launched", maybe by linking to explain.depesz.com >>=20 >> Out of an abundance of caution, our company has a policy of not = pasting our plans to public servers. However, I can confirm that when I = set max_parallel_workers_per_gather > 4 and the runtime increases, this = is what=E2=80=99s in the EXPLAIN ANALYZE output: >>=20 >> Workers Planned: 1 >> Workers Launched: 1 >=20 > Can you please verify the amount of max_parallel_workers and = max_worker_processes? It should be roughly max_worker_processes > = max_parallel_workers > max_parallel_workers_per_gather, for instance: >=20 > max_worker_processes =3D 24 > max_parallel_workers =3D 18 > max_parallel_workers_per_gather =3D 6 I changed my settings to these exact values and can still recreate the = situation where I unexpectedly get a single worker query. > Also, there are more configuration settings related to parallel = queries you might want to look into. Most notably: >=20 > parallel_setup_cost > parallel_tuple_cost > min_parallel_table_scan_size >=20 > Especially the last one is a typical dealbreaker, you can try to set = it to 0 for the beginning. Good starters for the others are 500 and 0.1 = respectively. Aha! By setting min_parallel_table_scan_size=3D0, Postgres uses the 6 = workers I expect, and the execution time decreases nicely.=20 I posted a clumsily-anonymized plan for the =E2=80=9Cbad=E2=80=9D = scenario here -- https://gist.github.com/osvenskan/ea00aa71abaa9697ade0ab7c1f3b705b There are 3 sort nodes in the plan. When I get the =E2=80=9Cbad=E2=80=9D = behavior, the sorts have one worker, when I get the good behavior, they = have multiple workers (e.g. 6). This brings up a couple of questions =E2=80=94 1) I=E2=80=99ve read that this is Postgres=E2=80=99 formula for the max = # of workers it will consider for a table =E2=80=94 max_workers =3D log3(table size / min_parallel_table_scan_size) Does that use the raw table size, or does the planner use statistics to = estimate the size of the subset of the table that will be read before = allocating workers? 2) There are 9 tables in this query ranging in size from 72Kb to 17Gb. = Does Postgres decide on a table-by-table basis to allocate multiple = workers, or=E2=80=A6? Thank you so much for the suggestion, I feel un-stuck now that I have an = idea to experiment with. Cheers Philip