Disallowing setting the max_spare_children greater than num_init_children.
authorMuhammad Usama <m.usama@gmail.com>
Sat, 22 Jul 2023 13:54:31 +0000 (18:54 +0500)
committerMuhammad Usama <m.usama@gmail.com>
Sat, 22 Jul 2023 13:56:25 +0000 (18:56 +0500)
Config post-processing stage now throws an error if num_init_children is
smaller than max_spare_children.
Commit also adjusts the number of child processes spawned at startup based on
the configured process management strategy.
For the Aggressive strategy, max_spare_children number of processes is spawned;
for the other two strategies, min_spare_children number of children gets
created at startup.

src/config/pool_config_variables.c
src/main/pgpool_main.c

index 3373f04f9525e9eeae9af42265df8d2110c017bc..faa677698120fe02247a55cedf7935948949570c 100644 (file)
@@ -4966,6 +4966,13 @@ config_post_processor(ConfigContext context, int elevel)
                                pool_config->max_spare_children,pool_config->min_spare_children)));
                return false;
        }
+       if (pool_config->num_init_children < pool_config->max_spare_children)
+       {
+               ereport(elevel,
+                               (errmsg("invalid configuration, max_spare_children:%d can't be greater than num_init_children:%d",
+                               pool_config->max_spare_children,pool_config->num_init_children)));
+               return false;
+       }
        return true;
 }
 
index dc2ff1faba1361c258637d127d200ea5550694da..252ea6da23b646e91ab17f2229e2286b513ee520 100644 (file)
@@ -538,11 +538,16 @@ PgpoolMain(bool discard_status, bool clear_memcache_oidmaps)
        POOL_SETMASK(&BlockSig);
 
        if (pool_config->process_management == PM_DYNAMIC)
-               current_child_process_count = pool_config->max_spare_children;
+       {
+               if (pool_config->process_management_strategy == PM_STRATEGY_AGGRESSIVE)
+                       current_child_process_count = pool_config->max_spare_children;
+               else
+                       current_child_process_count = pool_config->min_spare_children;
+       }
        else
                current_child_process_count = pool_config->num_init_children;
-
-       /* fork the children */
+       ereport(DEBUG1,
+            (errmsg("Spawning %d child processes",current_child_process_count)));
        for (i = 0; i < current_child_process_count; i++)
        {
                process_info[i].start_time = time(NULL);