Introduce two fields in EState to track parallel worker activity
authorMichael Paquier <[email protected]>
Tue, 8 Oct 2024 23:07:48 +0000 (08:07 +0900)
committerMichael Paquier <[email protected]>
Tue, 8 Oct 2024 23:07:48 +0000 (08:07 +0900)
These fields can be set by executor nodes to record how many parallel
workers were planned to be launched and how many of them have been
actually launched within the number initially planned.  This data is
able to give an approximation of the parallel worker draught a system
is facing, making easier the tuning of related configuration parameters.

These fields will be used by some follow-up patches to populate other
parts of the system with their data.

Author: Guillaume Lelarge, Benoit Lobréau
Discussion: https://postgr.es/m/783bc7f7-659a-42fa-99dd-ee0565644e25@dalibo.com
Discussion: https://postgr.es/m/CAECtzeWtTGOK0UgKXdDGpfTVSa5bd_VbUt6K6xn8P7X+_dZqKw@mail.gmail.com

src/backend/executor/execUtils.c
src/backend/executor/nodeGather.c
src/backend/executor/nodeGatherMerge.c
src/include/nodes/execnodes.h

index 5737f9f4ebd5295cab63a2774136ec0a09b05ff1..6712302ec8c68d74681b2bd72aebfc18855be232 100644 (file)
@@ -158,6 +158,8 @@ CreateExecutorState(void)
        estate->es_sourceText = NULL;
 
        estate->es_use_parallel_mode = false;
+       estate->es_parallel_workers_to_launch = 0;
+       estate->es_parallel_workers_launched = 0;
 
        estate->es_jit_flags = 0;
        estate->es_jit = NULL;
index 5d4ffe989cb2345e7857a158e0b1960137d408b0..7f7edc7f9fc8184fea4e553511619c3e90ab6ecc 100644 (file)
@@ -182,6 +182,13 @@ ExecGather(PlanState *pstate)
                        /* We save # workers launched for the benefit of EXPLAIN */
                        node->nworkers_launched = pcxt->nworkers_launched;
 
+                       /*
+                        * Count number of workers originally wanted and actually
+                        * launched.
+                        */
+                       estate->es_parallel_workers_to_launch += pcxt->nworkers_to_launch;
+                       estate->es_parallel_workers_launched += pcxt->nworkers_launched;
+
                        /* Set up tuple queue readers to read the results. */
                        if (pcxt->nworkers_launched > 0)
                        {
index 45f6017c29ef89e7befed59d08c4d81685f27c72..bc99c0b4485a4766fd9f4e4bb0634914877f0176 100644 (file)
@@ -223,6 +223,13 @@ ExecGatherMerge(PlanState *pstate)
                        /* We save # workers launched for the benefit of EXPLAIN */
                        node->nworkers_launched = pcxt->nworkers_launched;
 
+                       /*
+                        * Count number of workers originally wanted and actually
+                        * launched.
+                        */
+                       estate->es_parallel_workers_to_launch += pcxt->nworkers_to_launch;
+                       estate->es_parallel_workers_launched += pcxt->nworkers_launched;
+
                        /* Set up tuple queue readers to read the results. */
                        if (pcxt->nworkers_launched > 0)
                        {
index aab59d681cf5c0fd6908b23b868cd0b018ce2957..e4698a28c4f0c03b9a4262a781225942d2e51afd 100644 (file)
@@ -708,6 +708,11 @@ typedef struct EState
 
        bool            es_use_parallel_mode;   /* can we use parallel workers? */
 
+       int                     es_parallel_workers_to_launch;  /* number of workers to
+                                                                                                * launch. */
+       int                     es_parallel_workers_launched;   /* number of workers actually
+                                                                                                * launched. */
+
        /* The per-query shared memory area to use for parallel execution. */
        struct dsa_area *es_query_dsa;