PostgreSQL 11 preview - pgbench 压测软件增强

本文涉及的产品
云原生数据库 PolarDB 分布式版,标准版 2核8GB
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS PostgreSQL Serverless,0.5-4RCU 50GB 3个月
推荐场景:
对影评进行热评分析
简介:

标签

PostgreSQL , pgbench , 增强 , 11


背景

PostgreSQL 11 pgbench压测软件增强。

详细用法参考, pgbench非常强大,且性能非常好。

https://www.postgresql.org/docs/devel/static/pgbench.html

使用pgbench实施的一些压测场景

《HTAP数据库 PostgreSQL 场景与性能测试之 45 - (OLTP) 数据量与性能的线性关系(10亿+无衰减), 暨单表多大需要分区》

《[未完待续] HTAP数据库 PostgreSQL 场景与性能测试之 44 - (OLTP) 空间应用 - 空间包含查询(输入多边形 包含 表内空间对象)》

《HTAP数据库 PostgreSQL 场景与性能测试之 43 - (OLTP+OLAP) unlogged table 含索引多表批量写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 42 - (OLTP+OLAP) unlogged table 不含索引多表批量写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 41 - (OLTP+OLAP) 含索引多表批量写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 40 - (OLTP+OLAP) 不含索引多表批量写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 39 - (OLTP+OLAP) 含索引多表单点写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 38 - (OLTP+OLAP) 不含索引多表单点写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 37 - (OLTP+OLAP) 含索引单表批量写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 36 - (OLTP+OLAP) 不含索引单表批量写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 35 - (OLTP+OLAP) 含索引单表单点写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 34 - (OLTP+OLAP) 不含索引单表单点写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 33 - (OLAP) 物联网 - 线性字段区间实时统计》

《HTAP数据库 PostgreSQL 场景与性能测试之 32 - (OLTP) 高吞吐数据进出(堆存、行扫、无需索引) - 阅后即焚(JSON + 函数流式计算)》

《HTAP数据库 PostgreSQL 场景与性能测试之 31 - (OLTP) 高吞吐数据进出(堆存、行扫、无需索引) - 阅后即焚(读写大吞吐并测)》

《HTAP数据库 PostgreSQL 场景与性能测试之 30 - (OLTP) 秒杀 - 高并发单点更新》

《HTAP数据库 PostgreSQL 场景与性能测试之 29 - (OLTP) 空间应用 - 高并发空间位置更新(含空间索引)》

《HTAP数据库 PostgreSQL 场景与性能测试之 28 - (OLTP) 高并发点更新》

《HTAP数据库 PostgreSQL 场景与性能测试之 27 - (OLTP) 物联网 - FEED日志, 流式处理 与 阅后即焚 (CTE)》

《HTAP数据库 PostgreSQL 场景与性能测试之 26 - (OLTP) NOT IN、NOT EXISTS 查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 25 - (OLTP) IN , EXISTS 查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 24 - (OLTP) 物联网 - 时序数据并发写入(含时序索引BRIN)》

《HTAP数据库 PostgreSQL 场景与性能测试之 23 - (OLAP) 并行计算》

《HTAP数据库 PostgreSQL 场景与性能测试之 22 - (OLTP) merge insert|upsert|insert on conflict|合并写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 21 - (OLTP+OLAP) 排序、建索引》

《HTAP数据库 PostgreSQL 场景与性能测试之 20 - (OLAP) 用户画像圈人场景 - 多个字段任意组合条件筛选与透视》

《HTAP数据库 PostgreSQL 场景与性能测试之 19 - (OLAP) 用户画像圈人场景 - 数组相交查询与聚合》

《HTAP数据库 PostgreSQL 场景与性能测试之 18 - (OLAP) 用户画像圈人场景 - 数组包含查询与聚合》

《HTAP数据库 PostgreSQL 场景与性能测试之 17 - (OLTP) 数组相似查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 16 - (OLTP) 文本特征向量 - 相似特征(海明...)查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 15 - (OLTP) 物联网 - 查询一个时序区间的数据》

《HTAP数据库 PostgreSQL 场景与性能测试之 14 - (OLTP) 字符串搜索 - 全文检索》

《HTAP数据库 PostgreSQL 场景与性能测试之 13 - (OLTP) 字符串搜索 - 相似查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 12 - (OLTP) 字符串搜索 - 前后模糊查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 11 - (OLTP) 字符串搜索 - 后缀查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 10 - (OLTP) 字符串搜索 - 前缀查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 9 - (OLTP) 字符串模糊查询 - 含索引实时写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 8 - (OLTP) 多值类型(数组)含索引实时写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 7 - (OLTP) 全文检索 - 含索引实时写入》

《HTAP数据库 PostgreSQL 场景与性能测试之 6 - (OLTP) 空间应用 - KNN查询(搜索附近对象,由近到远排序输出)》

《HTAP数据库 PostgreSQL 场景与性能测试之 5 - (OLTP) 空间应用 - 空间包含查询(表内多边形 包含 输入空间对象)》

《HTAP数据库 PostgreSQL 场景与性能测试之 4 - (OLAP) 大表OUTER JOIN统计查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 3 - (OLAP) 大表JOIN统计查询》

《HTAP数据库 PostgreSQL 场景与性能测试之 2 - (OLTP) 多表JOIN》

《HTAP数据库 PostgreSQL 场景与性能测试之 1 - (OLTP) 点查》

E.1.3.9.2. pgbench

  • Add pgbench expressions support for NULLs, booleans, and some functions and operators (Fabien Coelho)

支持更加丰富的变量设置

\set varname expression  
    Sets variable varname to a value calculated from expression. 
   The expression may contain the NULL constant, boolean 
   constants TRUE and FALSE, integer constants such as 5432, 
   double constants such as 3.14159, references to  
    variables :variablename, operators with their usual SQL 
   precedence and associativity, function calls, SQL CASE 
   generic conditional expressions and parentheses.  

    Functions and most operators return NULL on NULL input.  

    For conditional purposes, non zero numerical values are 
   TRUE, zero numerical values and NULL are FALSE.  

    When no final ELSE clause is provided to a CASE, the default value is NULL.  

    Examples:  

        \set ntellers 10 * :scale  
        \set aid (1021 * random(1, 100000 * :scale)) % \  
                   (100000 * :scale) + 1  
        \set divx CASE WHEN :x <> 0 THEN :y/:x ELSE NULL END  
  • Add \if conditional support to pgbench (Fabien Coelho)

支持if条件控制用法

\if expression  
\elif expression  
\else  
\endif  
  This group of commands implements nestable conditional blocks, 
  similarly to psql's \if expression. Conditional expressions 
  are identical to those with \set, with non-zero values 
  interpreted as true.  

类似psql的if用法

\if expression  
\elif expression  
\else  
\endif  
  This group of commands implements nestable conditional blocks. 
  A conditional block must begin with an \if and end with an \endif. 
  In between there may be any number of \elif clauses, which 
  may optionally be followed by a  
  single \else clause. Ordinary queries and other types of backslash 
  commands may (and usually do) appear between the commands forming 
  a conditional block.  
  
  The \if and \elif commands read their argument(s) and evaluate 
  them as a boolean expression. If the expression yields true then 
  processing continues normally; otherwise, lines are skipped until 
  a matching \elif, \else,  
  or \endif is reached. Once an \if or \elif test has succeeded, 
  the arguments of later \elif commands in the same block are not 
  evaluated but are treated as false. Lines following an \else are 
  processed only if no earlier  
  matching \if or \elif succeeded.  
  
  The expression argument of an \if or \elif command is subject to 
  variable interpolation and backquote expansion, just like any 
  other backslash command argument. After that it is evaluated 
  like the value of an on/off  
  option variable. So a valid value is any unambiguous case-insensitive 
  match for one of: true, false, 1, 0, on, off, yes, no. 
  For example, t, T, and tR will all be considered to be true.  
  
  Expressions that do not properly evaluate to true or false will 
  generate a warning and be treated as false.  
  
  Lines being skipped are parsed normally to identify queries and 
  backslash commands, but queries are not sent to the server, 
  and backslash commands other than conditionals (\if, \elif, \else, \endif) are ignored.  
  Conditional commands are checked only for valid nesting.
  Variable references in skipped lines are not expanded, and backquote 
  expansion is not performed either.  
  
  All the backslash commands of a given conditional block must appear 
  in the same source file. If EOF is reached on the main input file 
  or an \include-ed file before all local \if-blocks have been closed, 
  then psql will  
  raise an error.  
  
  Here is an example:  
  
    -- check for the existence of two separate records in the database and store  
    -- the results in separate psql variables  
    SELECT  
        EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer,  
        EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee  
    \gset  
    \if :is_customer  
        SELECT * FROM customer WHERE customer_id = 123;  
    \elif :is_employee  
        \echo 'is not a customer but is an employee'  
        SELECT * FROM employee WHERE employee_id = 456;  
    \else  
        \if yes  
            \echo 'not a customer or employee'  
        \else  
            \echo 'this will never print'  
        \endif  
    \endif  
  • Allow the use of non-ASCII characters in pgbench variable names (Fabien Coelho)

  • Add pgbench option --init-steps to control the initialization steps performed (Masahiko Sawada)

增加前奏操作,目前感觉还只围绕TPC-B来做前奏,建议后面加script用户自定义前奏。

-I init_steps  
--init-steps=init_steps  
    Perform just a selected set of the normal initialization steps.  
   init_steps specifies the initialization steps to be performed, 
   using one character per step. Each step is invoked in the 
   specified order. The default is  
    dtgvp. The available steps are:  

    d (Drop)  
        Drop any existing pgbench tables.  

    t (create Tables)  
        Create the tables used by the standard pgbench scenario, 
       namely pgbench_accounts, pgbench_branches, pgbench_history, 
       and pgbench_tellers.  

    g (Generate data)  
        Generate data and load it into the standard tables, 
       replacing any data already present.  

    v (Vacuum)  
        Invoke VACUUM on the standard tables.  

    p (create Primary keys)  
        Create primary key indexes on the standard tables.  

    f (create Foreign keys)  
        Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)  
  • Add approximated Zipfian-distributed random generator to pgbench (Alik Khilazhev)

增加Zipfian-distributed随机分布值的产生函数,可以生成需要Zipf分布的数据。Zipf分布数据的背景知识:

https://baike.baidu.com/item/Zipf%E5%AE%9A%E5%BE%8B

1935年,哈佛大学的语言学专家Zipf在研究英文单词出现的频率时,发现如果把单词出现的频率按由大到小的顺序排列,则每个单词出现的频率与它的名次的常数次幂存在简单的反比关系,这种分布就称为Zipf定律,它表明在英语单词中,只有极少数的词被经常使用,而绝大多数词很少被使用.实际上,包括汉语在内的许多国家的语言都有这种特点。这个定律后来在很多领域得到了同样的验证,包括网站的访问者数量、城镇的大小和每个国家公司的数量。

相信你一定听过这样的说法:

80%的财富集中在20%的人手中……

80%的用户只使用20%的功能……

20%的用户贡献了80%的访问量……

…………

你知道我在说“二八原则”或“20/80原则”,是的,没错!


如果把所有的单词(字)放在一起看呢?会不会20%的词(字)占了80%的出现次数?答案是肯定的。

早在上个世纪30年代,就有人(Zipf)对此作出了研究,并给出了量化的表达——齐普夫定律(Zipf's Law):一个词在一个有相当长度的语篇中的等级序号(该词在按出现次数排列的词表中的位置,他称之为rank,简称r)与该词的出现频率(他称为frequency,简称f)的乘积几乎是一个常数(constant,简称C)。用公式表示,就是 r × f = C 。

·   random_zipfian generates an approximated bounded zipfian 
distribution. For parameter in (0, 1), an approximated algorithm 
is taken from "Quickly Generating Billion-Record Synthetic Databases", 
Jim Gray et al, SIGMOD  
    1994. For parameter in (1, 1000), a rejection method is used, 
   based on "Non-Uniform Random Variate Generation", Luc Devroye, 
   p. 550-551, Springer 1986. The distribution is not defined 
   when the parameter's value is 1.0.  
    The drawing performance is poor for parameter values close 
   and above 1.0 and on a small range.  

    parameter defines how skewed the distribution is. The larger 
   the parameter, the more frequently values to the beginning 
   of the interval are drawn. The closer to 0 parameter is, 
   the flatter (more uniform) the access  
    distribution.  

Hash functions hash, hash_murmur2 and hash_fnv1a accept an input 
value and an optional seed parameter. In case the seed isn't 
provided the value of :default_seed is used, which is initialized 
randomly unless set by the  
command-line -D option. Hash functions can be used to scatter the 
distribution of random functions such as random_zipfian or 
random_exponential. For instance, the following pgbench script 
simulates possible real world  
workload typical for social media and blogging platforms where 
few accounts generate excessive load:  

    \set r random_zipfian(0, 100000000, 1.07)  
  • Allow the random seed to be set in pgbench (Fabien Coelho)
--random-seed=SEED  
  Set random generator seed. Seeds the system random number generator, 
  which then produces a sequence of initial generator states, one for 
  each thread. Values for SEED may be: time (the default, the seed is 
  based on the  
  current time), rand (use a strong random source, failing if none is 
  available), or an unsigned decimal integer value. The random generator 
  is invoked explicitly from a pgbench script (random...  functions) 
  or implicitly  
  (for instance option --rate uses it to schedule transactions). When 
  explicitly set, the value used for seeding is shown on the terminal. 
  Any value allowed for SEED may also be provided through the environment variable  
  PGBENCH_RANDOM_SEED. To ensure that the provided seed impacts all 
  possible uses, put this option first or use the environment variable.  
  
  Setting the seed explicitly allows to reproduce a pgbench run exactly, 
  as far as random numbers are concerned. As the random state is managed 
  per thread, this means the exact same pgbench run for an identical invocation  
  if there is one client per thread and there are no external or data 
  dependencies. From a statistical viewpoint reproducing runs exactly 
  is a bad idea because it can hide the performance variability or improve performance  
  unduly, e.g. by hitting the same pages as a previous run. However, 
  it may also be of great help for debugging, for instance re-running 
  a tricky case which leads to an error. Use wisely.  
  • Allow pgbench to do exponentiation with pow() and power() (Raúl Marín Rodríguez)

支持power函数.

  • Add hashing functions to pgbench (Ildar Musin)
Hash functions hash, hash_murmur2 and hash_fnv1a accept an input value and an 
optional seed parameter. In case the seed isn't provided the value of :default_seed is 
used, which is initialized randomly unless set by the command-line -D option. 
Hash functions can be used to scatter the distribution of random functions such 
as random_zipfian or random_exponential. For instance, the following pgbench 
script simulates possible real world workload typical for social media and 
blogging platforms where few accounts generate excessive load:  

\set r random_zipfian(0, 100000000, 1.07)  
\set k abs(hash(:r)) % 1000000  
  • Make pgbench statistics more accurate when using --latency-limit and --rate (Fabien Coelho)

提高统计精确度

相关实践学习
AnalyticDB MySQL海量数据秒级分析体验
快速上手AnalyticDB MySQL,玩转SQL开发等功能!本教程介绍如何在AnalyticDB MySQL中,一键加载内置数据集,并基于自动生成的查询脚本,运行复杂查询语句,秒级生成查询结果。
阿里云云原生数据仓库AnalyticDB MySQL版 使用教程
云原生数据仓库AnalyticDB MySQL版是一种支持高并发低延时查询的新一代云原生数据仓库,高度兼容MySQL协议以及SQL:92、SQL:99、SQL:2003标准,可以对海量数据进行即时的多维分析透视和业务探索,快速构建企业云上数据仓库。 了解产品 https://www.aliyun.com/product/ApsaraDB/ads
目录
相关文章
|
关系型数据库 分布式数据库 数据库
沉浸式学习PostgreSQL|PolarDB 19: 体验最流行的开源企业ERP软件 odoo
本文主要教大家怎么用好数据库, 而不是怎么运维管理数据库、怎么开发数据库内核.
1122 2
|
6月前
|
SQL 关系型数据库 测试技术
postgresql|数据库|数据库测试工具pgbench之使用
postgresql|数据库|数据库测试工具pgbench之使用
294 0
|
关系型数据库 分布式数据库 PolarDB
沉浸式学习PostgreSQL|PolarDB 15: 企业ERP软件、网站、分析型业务场景、营销场景人群圈选, 任意字段组合条件数据筛选
本篇文章目标学习如何快速在任意字段组合条件输入搜索到满足条件的数据.
611 0
|
供应链 Oracle 关系型数据库
|
SQL 关系型数据库 数据挖掘
PolarDB for PostgreSQL 开源必读手册-最佳场景实践与压测(下)
PolarDB for PostgreSQL 开源必读手册-最佳场景实践与压测
215 0
PolarDB for PostgreSQL 开源必读手册-最佳场景实践与压测(下)
|
Java 测试技术 应用服务中间件
压测软件,JMeter5.4.1版本下载及环境变量配置
压测软件,JMeter5.4.1版本下载及环境变量配置
1048 0
压测软件,JMeter5.4.1版本下载及环境变量配置
|
缓存 分布式计算 负载均衡
软件性能测试(连载20)
软件性能测试(连载20)
111 0
软件性能测试(连载20)
|
SQL 监控 前端开发
软件性能测试(连载19)
软件性能测试(连载19)
133 0
软件性能测试(连载19)
|
存储 SQL 安全
软件性能测试(连载18)
软件性能测试(连载18)
161 0
软件性能测试(连载18)
|
机器学习/深度学习 监控 NoSQL
软件性能测试(连载16)
软件性能测试(连载16)
137 0
软件性能测试(连载16)

相关产品

  • 云原生数据库 PolarDB
  • 云数据库 RDS PostgreSQL 版
  • 下一篇
    无影云桌面