实际并行workers数量不等于postgresql.conf中设置的max_parallel_workers_per_gather数量

1 前言

  • 本文件的源码来自PostgreSQL 14.5,其它版本略有不同
  • 并行workers并不能显箸提升性能。个人不建议使用并行worker进程,大多数情况下采用postgresql.conf默认配置即可。

PostgreSQL的并行workers是由compute_parallel_worker函数决定的,compute_parallel_worker是估算扫描所需的并行工作线程数,并不是您在postgresql.conf中设置的max_parallel_workers_per_gather数量,compute_parallel_worker会根据heap_pages、index_pages、max_workers(max_parallel_workers_per_gather)来决定并行工作线程数量。

2 源码和调用位置

compute_parallel_worker共有4个地方调用

src\backend\optimizer\path\allpaths.c(801,21)
src\backend\optimizer\path\allpaths.c(3724,21)
src\backend\optimizer\path\costsize.c(707,33)
src\backend\optimizer\plan\planner.c(5953,21)

compute_parallel_worker的声明

src\include\optimizer\paths.h(59,12)

compute_parallel_worker的实现

src\backend\optimizer\path\allpaths.c(3750,1)

compute_parallel_worker的源码

/** Compute the number of parallel workers that should be used to scan a* relation.  We compute the parallel workers based on the size of the heap to* be scanned and the size of the index to be scanned, then choose a minimum* of those.** "heap_pages" is the number of pages from the table that we expect to scan, or* -1 if we don't expect to scan any.** "index_pages" is the number of pages from the index that we expect to scan, or* -1 if we don't expect to scan any.** "max_workers" is caller's limit on the number of workers.  This typically* comes from a GUC.* "max_workers"就是postgresql.conf中max_parallel_workers_per_gather的值*/
int
compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages,int max_workers)
{int			parallel_workers = 0;/** If the user has set the parallel_workers reloption, use that; otherwise* select a default number of workers.* 不需要优化,直接来自表级存储参数parallel_workers* 详见第3节直接使用postgresql.conf中设置的max_parallel_workers_per_gather数量*/if (rel->rel_parallel_workers != -1)parallel_workers = rel->rel_parallel_workers;else{/** If the number of pages being scanned is insufficient to justify a* parallel scan, just return zero ... unless it's an inheritance* child. In that case, we want to generate a parallel path here* anyway.  It might not be worthwhile just for this relation, but* when combined with all of its inheritance siblings it may well pay* off.*/if (rel->reloptkind == RELOPT_BASEREL &&((heap_pages >= 0 && heap_pages < min_parallel_table_scan_size) ||(index_pages >= 0 && index_pages < min_parallel_index_scan_size)))return 0;if (heap_pages >= 0){int			heap_parallel_threshold;int			heap_parallel_workers = 1;/** Select the number of workers based on the log of the size of* the relation.  This probably needs to be a good deal more* sophisticated, but we need something here for now.  Note that* the upper limit of the min_parallel_table_scan_size GUC is* chosen to prevent overflow here.*/heap_parallel_threshold = Max(min_parallel_table_scan_size, 1);while (heap_pages >= (BlockNumber) (heap_parallel_threshold * 3)){heap_parallel_workers++;heap_parallel_threshold *= 3;if (heap_parallel_threshold > INT_MAX / 3)break;		/* avoid overflow */}parallel_workers = heap_parallel_workers;}if (index_pages >= 0){int			index_parallel_workers = 1;int			index_parallel_threshold;/* same calculation as for heap_pages above */index_parallel_threshold = Max(min_parallel_index_scan_size, 1);while (index_pages >= (BlockNumber) (index_parallel_threshold * 3)){index_parallel_workers++;index_parallel_threshold *= 3;if (index_parallel_threshold > INT_MAX / 3)break;		/* avoid overflow */}if (parallel_workers > 0)parallel_workers = Min(parallel_workers, index_parallel_workers);elseparallel_workers = index_parallel_workers;}}/* In no case use more than caller supplied maximum number of workers */parallel_workers = Min(parallel_workers, max_workers);return parallel_workers;
}

3 直接使用postgresql.conf中设置的max_parallel_workers_per_gather数量

如果要使用指定数量的并行worker数,必须使用存储参数parallel_workers。

alter table tab set (parallel_workers=8);

配置了存储参数后,compute_parallel_worker就不在对并行worker数优化,直接返回配置的parallel_workers数量。

if (rel->rel_parallel_workers != -1)parallel_workers = rel->rel_parallel_workers;
  • 注意:如果不设置表级存储参数parallel_workers,实际的并行工作线程数由compute_parallel_worker根据heap_pages、index_pages、max_workers来决定并行工作线程数量,因此会出现实际并行工作数量不等于postgresql.conf中设置的max_parallel_workers_per_gather的情况。
    在这里插入图片描述
    在这里插入图片描述

  • 在次强制:并行workers并不能显箸提升性能。个人不建议使用并行worker进程,大多数情况下采用postgresql.conf默认配置即可。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/119029.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【人工智能】—_线性分类器、感知机、损失函数的选取、最小二乘法分类、模型复杂性和过度拟合、规范化

文章目录 Linear predictions 线性预测分类线性分类器感知机感知机学习策略损失函数的选取距离的计算 最小二乘法分类求解最小二乘分类矩阵解法一般线性分类模型复杂性和过度拟合训练误差测试误差泛化误差复杂度与过拟合规范化 Linear predictions 线性预测 分类 从具有有限离…

MySQL-数据类型

MySQL-数据类型 数值类型bittinyintfloatdecimal 字符串和文本类型charvarcharblobtext 日期和时间类型enum-枚举类型set-集合类型 数值类型 数据类型说明bit(M)位类型。M指定位数&#xff0c;默认值为1&#xff0c;范围1-64.tinyint [unsigned]带符号范围:-128 - 127&#xf…

JavaScript 生成 16: 9 宽高比

这篇文章只是对 for 循环一个简单应用&#xff0c;没有什么知识含量。 可以跳过这篇文章。 只是我用来保存一下我的代码&#xff0c;保存在本地我嫌碍眼&#xff0c;总想把他删了。 正文部分 公式&#xff1a;其中 width 表示宽度&#xff0c;height 表示高度 16 9 w i d t…

【微服务部署】一、使用docker-compose部署Jenkins、SonarQube、PostgreSQL

一、安装 1、编写docker-compose部署Postgres、SonarQube、Jenkins的yml文件jenkins-compose.yml Postgres&#xff1a;作为SonarQube的数据库存储SonarQube&#xff1a;代码质量检查Jenkins&#xff1a;jenkins/jenkins:lts镜像&#xff0c;jenkinsci/blueocean镜像缺少node…

22.3D等距社交媒体菜单的悬停特效

效果 源码 <!doctype html> <html><head><meta charset="utf-8"><title>CSS Isometric Social Media Menu</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.…

Vue框架--理解MVVM

我们知道&#xff0c;MVVM是Model-View-ViewModel的简写。它本质上就是MVC的改进版。我们看看MVVM的模型架构&#xff0c;如下所示: 架构理解与实例

git大文件推送报错

报错信息 不多掰扯&#xff0c;直接上报错信息和截图 Delta compression using up to 8 threadsRPC failde; HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large从以上的报错信息不难看出推送仓库的时候&#xff0c;请求体过大&#xff0c;为…

供热管网安全运行监测,提升供热管网安全性能

城市管网是城市的“生命线”之一&#xff0c;是城市赖以生存和发展的基础&#xff0c;在城市基础设施高质量发展中发挥着重要作用。供热管网作为城市生命线中连接供热管线与热用户的桥梁&#xff0c;担负着向企业和居民用户直接供热的重要职责。随着城市热力需求的急剧增加&…

网络实验 VlAN 中 Trunk Access端口的说明及实验

网络实验 VlAN 中 Trunk Access端口的说明及实验 VlAN 虚拟局域网技术Access端口 工作原理Trunk端口 工作原理简单实验&#xff08;一&#xff09;划分不同Vlan&#xff0c;实现vlan内部通信拓朴图主机IP 配置划分Vlanping 测试 &#xff08;二&#xff09;跨交换机实现VLAN间通…

Java 复习笔记 - 学生管理系统篇

文章目录 学生管理系统一&#xff0c;需求部分需求分析初始菜单学生类添加功能删除功能修改功能查询功能 二&#xff0c;实现部分&#xff08;一&#xff09;初始化主界面&#xff08;二&#xff09;编写学生类&#xff08;三&#xff09;编写添加学生方法&#xff08;四&#…

坦克400 Hi4-T预售价28.5万元起,越野新能源好理解

8月25日&#xff0c;在以“智享蓉城&#xff0c;驭见未来”为主题的成都国际车展上&#xff0c;坦克品牌越野新能源再启新程&#xff0c;首次以全Hi4-T新能源阵容亮相展台&#xff0c;释放坦克品牌加速布局越野新能源的强烈信号。 Hi4-T架构首款落地车型坦克500 Hi4-T上市至今斩…

Kotlin判断null比较let布尔值Boolean

Kotlin判断null比较let布尔值Boolean class MyData {val count: Int? 2023val number: Int? null }fun main(args: Array<String>) {val data MyData()val year 2022if (data.count ! null) {if (data.count > year) {println("data.count ! null")}}…

Windows 操作系统下 Python 及其模块的管理

Python 是一款解释型语言&#xff0c;理论上一个.py文件可以当成一个稍微复杂一些的字符串指令集本文不涉及jupyter,VS,VScode,Pycharm 等集成开发环境&#xff0c;这不是我们这篇文章所关心的东西 这篇文章面向的是Python 的初学者 最近没有写太多长文章&#xff0c;多写几篇&…

工具分享 | PDF文档解析工具PyMuPDF

1 需求描述 最近工作需要从PDF文档中按照章节解析出对应的文本和图片(后续可能还会有表格)&#xff0c;经过调研&#xff0c;找到了一个功能强大的解析工具MuPDF&#xff0c;对应的Python包是PyMuPDF。本篇博客记录使用它来实现具体功能。 官方文档&#xff1a;https://pymupd…

WEB项目利用Eclipse打包成war包并部署在CentOS8

1、Eclipse把WEB项目打包成war包 2、Xftp上传war包到Linux中安装Tomcat的webapps目录 /usr/local/tomcat/apache-tomcat-9.0.80/webapps3、利用IP地址访问部署的项目 在CentOS中可用 ifconfig找到对应的IP地址 http://192.168.122.2:8080/CentOS-Web/index.html

CSS学习笔记02

CSS笔记02 美化网页元素 为什么要美化网页 目的&#xff1a; 有效的传递页面信息美化网页、页面漂亮、才能吸引用户突显页面的主题提高用户的体验 span标签 span标签是短语内容的通用行内容器&#xff0c;它本身并没有任何特殊语义。 通常我们使用span标签来把我们想要重…

Docker部署RustDesk Server 设置开机自启

三、Docker安装 Docker官方和国内daocloud都提供了一键安装的脚本&#xff0c;使得Docker的安装更加便捷。 官方的一键安装方式&#xff1a; curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 国内 daocloud一键安装命令&#xff1a; curl -sSL https://…

nmap的使用

目录 nmap简介 主要作用 nmap原理 namp使用 options nmap列举远程机器开放端口 普通扫描 扫描范围端口 对几个端口探测 对所有端口进行探测 指定协议探测端口 扫描对应协议的所有端口 端口状态 nmap识别目标机器上服务的指纹 服务指纹 识别目标机器服务信息 …

el-tree组件的锚点链接

el-tree部分&#xff1a; <el-tree:default-expand-all"true":data"anchorList":props"defaultProps"node-click"handleNodeClick"/> 组件内部部分&#xff1a; <div class"header" :id"content obj.id&q…

界面控件Telerik UI for WPF——Windows 11主题精简模式提升应用体验

Telerik UI for WPF拥有超过100个控件来创建美观、高性能的桌面应用程序&#xff0c;同时还能快速构建企业级办公WPF应用程序。Telerik UI for WPF支持MVVM、触摸等&#xff0c;创建的应用程序可靠且结构良好&#xff0c;非常容易维护&#xff0c;其直观的API将无缝地集成Visua…