首页 > 数据库 >学习使用benchmarksql压测数据库

学习使用benchmarksql压测数据库

时间:2023-05-04 15:58:18浏览次数:58  
标签:INFO Term 22 压测 数据库 00 benchmarksql bmsql id

介绍

benchmarksql是一款符合TPC-C基准压力测试工具,TPC-C是衡量在线事务处理的基准。

TPC-C模型是模拟一个商品批发公司的销售模型,这个模型涵盖了一个批发公司面向客户对一系列商品进行销售的过程,这包括管理订单,管理库存,管理账号收支等操作。这些操作涉及到仓库、商品、客户、订单等概念,围绕这些概念,构造了数据表格,以及相应的数据库操作。

benchmarksql默认提供了三种数据库压测脚本(firebird、oracle、postgres),可以根据需要修改配置文件。

为了快速地学习benmarksql可以参考“腾讯云”上的两篇文章:

压测postgres

环境介绍

操作系统:CentOS 7.6
Java:1.8.0_181

安装benchmarksql

下载benchmarksql:https://sourceforge.net/projects/benchmarksql/

安装benchmarksql

[root]# yum install ant -y
[root]# unzip benchmarksql-5.0.zip
[root]# cd benchmarksql-5.0
[root]# ant
Buildfile: /root/benchmarksql-5.0/build.xml

init:
    [mkdir] Created dir: /root/benchmarksql-5.0/build

compile:
    [javac] Compiling 11 source files to /root/benchmarksql-5.0/build

dist:
    [mkdir] Created dir: /root/benchmarksql-5.0/dist
      [jar] Building jar: /root/benchmarksql-5.0/dist/BenchmarkSQL-5.0.jar

BUILD SUCCESSFUL
Total time: 8 seconds

替换postgres JDBC驱动

根据个人环境来判断是否需要更新postgres JDBC驱动

[root]# cd /root/benchmarksql-5.0/lib/postgres
[root]# mv postgresql-9.3-1102.jdbc41.jar postgresql-9.3-1102.jdbc41.jar_20230428
[root]# wget https://jdbc.postgresql.org/download/postgresql-42.6.0.jar

postgres端创建压测用户和库

postgres=# CREATE USER benchmarksql WITH ENCRYPTED PASSWORD 'PostgreSQL5432';
postgres=# CREATE DATABASE benchmarksql OWNER benchmarksql;

配置postgres.props 

 

[root]# cd /root/benchmarksql-5.0/run
[root]# cp props.pg postgres.props
[root]# vi postgres.props
db=postgres
driver=org.postgresql.Driver
conn=jdbc:postgresql://192.168.1.71:5496/benchmarksql
user=benchmarksql
password=PostgreSQL5432

warehouses=1
loadWorkers=4

terminals=1
//To run specified transactions per terminal- runMins must equal zero
runTxnsPerTerminal=10
//To run for specified minutes- runTxnsPerTerminal must equal zero
runMins=0
//Number of total transactions per minute
limitTxnsPerMin=300

//Set to true to run in 4.x compatible mode. Set to false to use the
//entire configured database evenly.
terminalWarehouseFixed=true

//The following five values must add up to 100
//The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4

// Directory name to create for collecting detailed result data.
// Comment this out to suppress.
resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS
osCollectorScript=./misc/os_collector_linux.py
osCollectorInterval=1
//osCollectorSSHAddr=user@dbhost
osCollectorDevices=net_ens33 blk_sda

注释:

  • db=postgres 指定数据库类型,当前类型为postgres
  • driver=org.postgresql.Driver postgres数据库的JDBC驱动
  • conn=jdbc:postgresql://192.168.1.71:5496/benchmarksql postgres的连接字符串,格式为:conn=jdbc:postgresql://IP:端口/库名
  • user=benchmarksql 连接postgres的用户名
  • password=PostgreSQL5432 连接postgres的用户名的密码
  • warehouses=1 仓库数量,每个warehouse数据量大概在100MB左右,那么数据库大小为1000MB左右,默认1个仓库
  • loadWorkers=4 数据库初始化数据时候的进程数,默认4个load加载进程
  • terminals=1 指定终端数量,默认1个终端
  • runTxnsPerTerminal=10 指定压测每个终端执行的事务数量。如果该参数配置为非0时,下面的runMins参数必须设置为0
  • runMins=0  指定压测的时长(单位:分钟)。如果该值设置为非0值时,runTxnsPerTerminal参数必须设置为0。
  • limitTxnsPerMin=300 每分钟事务总数限制,该参数主要控制每分钟处理的事务数,事务数受terminals参数的影响,limitTxnsPerMin/terminals的值必须是正整数。
  • terminalWarehouseFixed=true 终端和仓库的绑定模式,设置为true时可以运行4.x兼容模式,意思为每个终端都有一个固定的仓库。设置为false时可以均匀的使用数据库整体配置。TPCC规定每个终端都必须有一个绑定的仓库,所以一般使用默认值true。
  • 下面五个值的总和必须等于100,默认值为:45, 43, 4, 4,4 ,与TPC-C测试定义的比例一致,实际操作过程中,可以调整比重来适应各种场景。
    • newOrderWeight=45  新订单事务占总事务的45%
    • paymentWeight=43    支付订单事务占总事务的43%
    • orderStatusWeight=4  订单状态事务占总事务的4%
    • deliveryWeight=4        到货日期事务占总事务的4%
    • stockLevelWeight=4    查看现存货品的事务占总事务的4%
  •  resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS 压测期间收集系统性能数据的目录(无需修改)
  • osCollectorScript=./misc/os_collector_linux.py 操作系统性能收集脚本(无需修改)
  • osCollectorInterval=1 操作系统收集操作间隔,默认为1秒
  • osCollectorSSHAddr=user@dbhost 需要收集系统性能的主机
  • osCollectorDevices=net_eth0 blk_sda 操作系统中被收集服务器的网卡名称和磁盘名称,根据个人环境进行调整

 初始化环境

创建相应的表并加载数据

[root]# cd /root/benchmarksql-5.0/run
[root]# ./runDatabaseBuild.sh postgres.props 
# ------------------------------------------------------------
# Loading SQL file ./sql.common/tableCreates.sql
# ------------------------------------------------------------
create table bmsql_config (
cfg_name    varchar(30) primary key,
cfg_value   varchar(50)
);
create table bmsql_warehouse (
w_id        integer   not null,
w_ytd       decimal(12,2),
w_tax       decimal(4,4),
w_name      varchar(10),
w_street_1  varchar(20),
w_street_2  varchar(20),
w_city      varchar(20),
w_state     char(2),
w_zip       char(9)
);
create table bmsql_district (
d_w_id       integer       not null,
d_id         integer       not null,
d_ytd        decimal(12,2),
d_tax        decimal(4,4),
d_next_o_id  integer,
d_name       varchar(10),
d_street_1   varchar(20),
d_street_2   varchar(20),
d_city       varchar(20),
d_state      char(2),
d_zip        char(9)
);
create table bmsql_customer (
c_w_id         integer        not null,
c_d_id         integer        not null,
c_id           integer        not null,
c_discount     decimal(4,4),
c_credit       char(2),
c_last         varchar(16),
c_first        varchar(16),
c_credit_lim   decimal(12,2),
c_balance      decimal(12,2),
c_ytd_payment  decimal(12,2),
c_payment_cnt  integer,
c_delivery_cnt integer,
c_street_1     varchar(20),
c_street_2     varchar(20),
c_city         varchar(20),
c_state        char(2),
c_zip          char(9),
c_phone        char(16),
c_since        timestamp,
c_middle       char(2),
c_data         varchar(500)
);
create sequence bmsql_hist_id_seq;
create table bmsql_history (
hist_id  integer,
h_c_id   integer,
h_c_d_id integer,
h_c_w_id integer,
h_d_id   integer,
h_w_id   integer,
h_date   timestamp,
h_amount decimal(6,2),
h_data   varchar(24)
);
create table bmsql_new_order (
no_w_id  integer   not null,
no_d_id  integer   not null,
no_o_id  integer   not null
);
create table bmsql_oorder (
o_w_id       integer      not null,
o_d_id       integer      not null,
o_id         integer      not null,
o_c_id       integer,
o_carrier_id integer,
o_ol_cnt     integer,
o_all_local  integer,
o_entry_d    timestamp
);
create table bmsql_order_line (
ol_w_id         integer   not null,
ol_d_id         integer   not null,
ol_o_id         integer   not null,
ol_number       integer   not null,
ol_i_id         integer   not null,
ol_delivery_d   timestamp,
ol_amount       decimal(6,2),
ol_supply_w_id  integer,
ol_quantity     integer,
ol_dist_info    char(24)
);
create table bmsql_item (
i_id     integer      not null,
i_name   varchar(24),
i_price  decimal(5,2),
i_data   varchar(50),
i_im_id  integer
);
create table bmsql_stock (
s_w_id       integer       not null,
s_i_id       integer       not null,
s_quantity   integer,
s_ytd        integer,
s_order_cnt  integer,
s_remote_cnt integer,
s_data       varchar(50),
s_dist_01    char(24),
s_dist_02    char(24),
s_dist_03    char(24),
s_dist_04    char(24),
s_dist_05    char(24),
s_dist_06    char(24),
s_dist_07    char(24),
s_dist_08    char(24),
s_dist_09    char(24),
s_dist_10    char(24)
);
Starting BenchmarkSQL LoadData

driver=org.postgresql.Driver
conn=jdbc:postgresql://192.168.1.71:5496/benchmarksql
user=benchmarksql
password=***********
warehouses=1
loadWorkers=4
fileLocation (not defined)
csvNullValue (not defined - using default 'NULL')

Worker 000: Loading ITEM
Worker 001: Loading Warehouse      1
Worker 000: Loading ITEM done
Worker 001: Loading Warehouse      1 done
# ------------------------------------------------------------
# Loading SQL file ./sql.common/indexCreates.sql
# ------------------------------------------------------------
alter table bmsql_warehouse add constraint bmsql_warehouse_pkey
primary key (w_id);
alter table bmsql_district add constraint bmsql_district_pkey
primary key (d_w_id, d_id);
alter table bmsql_customer add constraint bmsql_customer_pkey
primary key (c_w_id, c_d_id, c_id);
create index bmsql_customer_idx1
on  bmsql_customer (c_w_id, c_d_id, c_last, c_first);
alter table bmsql_oorder add constraint bmsql_oorder_pkey
primary key (o_w_id, o_d_id, o_id);
create unique index bmsql_oorder_idx1
on  bmsql_oorder (o_w_id, o_d_id, o_carrier_id, o_id);
alter table bmsql_new_order add constraint bmsql_new_order_pkey
primary key (no_w_id, no_d_id, no_o_id);
alter table bmsql_order_line add constraint bmsql_order_line_pkey
primary key (ol_w_id, ol_d_id, ol_o_id, ol_number);
alter table bmsql_stock add constraint bmsql_stock_pkey
primary key (s_w_id, s_i_id);
alter table bmsql_item add constraint bmsql_item_pkey
primary key (i_id);
# ------------------------------------------------------------
# Loading SQL file ./sql.common/foreignKeys.sql
# ------------------------------------------------------------
alter table bmsql_district add constraint d_warehouse_fkey
foreign key (d_w_id)
references bmsql_warehouse (w_id);
alter table bmsql_customer add constraint c_district_fkey
foreign key (c_w_id, c_d_id)
references bmsql_district (d_w_id, d_id);
alter table bmsql_history add constraint h_customer_fkey
foreign key (h_c_w_id, h_c_d_id, h_c_id)
references bmsql_customer (c_w_id, c_d_id, c_id);
alter table bmsql_history add constraint h_district_fkey
foreign key (h_w_id, h_d_id)
references bmsql_district (d_w_id, d_id);
alter table bmsql_new_order add constraint no_order_fkey
foreign key (no_w_id, no_d_id, no_o_id)
references bmsql_oorder (o_w_id, o_d_id, o_id);
alter table bmsql_oorder add constraint o_customer_fkey
foreign key (o_w_id, o_d_id, o_c_id)
references bmsql_customer (c_w_id, c_d_id, c_id);
alter table bmsql_order_line add constraint ol_order_fkey
foreign key (ol_w_id, ol_d_id, ol_o_id)
references bmsql_oorder (o_w_id, o_d_id, o_id);
alter table bmsql_order_line add constraint ol_stock_fkey
foreign key (ol_supply_w_id, ol_i_id)
references bmsql_stock (s_w_id, s_i_id);
alter table bmsql_stock add constraint s_warehouse_fkey
foreign key (s_w_id)
references bmsql_warehouse (w_id);
alter table bmsql_stock add constraint s_item_fkey
foreign key (s_i_id)
references bmsql_item (i_id);
# ------------------------------------------------------------
# Loading SQL file ./sql.postgres/extraHistID.sql
# ------------------------------------------------------------
-- ----
-- Extra Schema objects/definitions for history.hist_id in PostgreSQL
-- ----
-- ----
--      This is an extra column not present in the TPC-C
--      specs. It is useful for replication systems like
--      Bucardo and Slony-I, which like to have a primary
--      key on a table. It is an auto-increment or serial
--      column type. The definition below is compatible
--      with Oracle 11g, using a sequence and a trigger.
-- ----
-- Adjust the sequence above the current max(hist_id)
select setval('bmsql_hist_id_seq', (select max(hist_id) from bmsql_history));
-- Make nextval(seq) the default value of the hist_id column.
alter table bmsql_history
alter column hist_id set default nextval('bmsql_hist_id_seq');
-- Add a primary key history(hist_id)
alter table bmsql_history add primary key (hist_id);
# ------------------------------------------------------------
# Loading SQL file ./sql.postgres/buildFinish.sql
# ------------------------------------------------------------
-- ----
-- Extra commands to run after the tables are created, loaded,
-- indexes built and extra's created.
-- PostgreSQL version.
-- ----
vacuum analyze;

开始压力测试

[root]# ./runBenchmark.sh postgres.props 
22:05:46,261 [main] INFO   jTPCC : Term-00, 
22:05:46,269 [main] INFO   jTPCC : Term-00, +-------------------------------------------------------------+
22:05:46,270 [main] INFO   jTPCC : Term-00,      BenchmarkSQL v5.0
22:05:46,270 [main] INFO   jTPCC : Term-00, +-------------------------------------------------------------+
22:05:46,270 [main] INFO   jTPCC : Term-00,  (c) 2003, Raul Barbosa
22:05:46,270 [main] INFO   jTPCC : Term-00,  (c) 2004-2016, Denis Lussier
22:05:46,398 [main] INFO   jTPCC : Term-00,  (c) 2016, Jan Wieck
22:05:46,398 [main] INFO   jTPCC : Term-00, +-------------------------------------------------------------+
22:05:46,398 [main] INFO   jTPCC : Term-00, 
22:05:46,399 [main] INFO   jTPCC : Term-00, db=postgres
22:05:46,399 [main] INFO   jTPCC : Term-00, driver=org.postgresql.Driver
22:05:46,399 [main] INFO   jTPCC : Term-00, conn=jdbc:postgresql://192.168.1.71:5496/benchmarksql
22:05:46,399 [main] INFO   jTPCC : Term-00, user=benchmarksql
22:05:46,399 [main] INFO   jTPCC : Term-00, 
22:05:46,399 [main] INFO   jTPCC : Term-00, warehouses=1
22:05:46,399 [main] INFO   jTPCC : Term-00, terminals=1
22:05:46,400 [main] INFO   jTPCC : Term-00, runTxnsPerTerminal=100
22:05:46,401 [main] INFO   jTPCC : Term-00, limitTxnsPerMin=300
22:05:46,401 [main] INFO   jTPCC : Term-00, terminalWarehouseFixed=true
22:05:46,401 [main] INFO   jTPCC : Term-00, 
22:05:46,401 [main] INFO   jTPCC : Term-00, newOrderWeight=45
22:05:46,401 [main] INFO   jTPCC : Term-00, paymentWeight=43
22:05:46,401 [main] INFO   jTPCC : Term-00, orderStatusWeight=4
22:05:46,401 [main] INFO   jTPCC : Term-00, deliveryWeight=4
22:05:46,401 [main] INFO   jTPCC : Term-00, stockLevelWeight=4
22:05:46,401 [main] INFO   jTPCC : Term-00, 
22:05:46,401 [main] INFO   jTPCC : Term-00, resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS
22:05:46,401 [main] INFO   jTPCC : Term-00, osCollectorScript=./misc/os_collector_linux.py
22:05:46,401 [main] INFO   jTPCC : Term-00, 
22:05:46,586 [main] INFO   jTPCC : Term-00, copied postgres.props to my_result_2023-04-28_220546/run.properties
22:05:46,586 [main] INFO   jTPCC : Term-00, created my_result_2023-04-28_220546/data/runInfo.csv for runID 8
22:05:46,588 [main] INFO   jTPCC : Term-00, writing per transaction results to my_result_2023-04-28_220546/data/result.csv
22:05:46,589 [main] INFO   jTPCC : Term-00, osCollectorScript=./misc/os_collector_linux.py
22:05:46,589 [main] INFO   jTPCC : Term-00, osCollectorInterval=1
22:05:46,589 [main] INFO   jTPCC : Term-00, osCollectorSSHAddr=null
22:05:46,589 [main] INFO   jTPCC : Term-00, osCollectorDevices=net_ens33 blk_sda
22:05:46,942 [main] INFO   jTPCC : Term-00,
22:05:47,351 [main] INFO   jTPCC : Term-00, C value for C_LAST during load: 49
22:05:47,351 [main] INFO   jTPCC : Term-00, C value for C_LAST this run:    163
22:05:47,351 [main] INFO   jTPCC : Term-00,                                                                                                                            Term-00, Running Aver22:06:07,707 [Thread-2] INFO   jTPCC : Term-00,  Memory Usage: 21MB / 178MB                              
22:06:07,708 [Thread-2] INFO   jTPCC : Term-00, 
22:06:07,708 [Thread-2] INFO   jTPCC : Term-00, Measured tpmC (NewOrders) = 139.23
22:06:07,708 [Thread-2] INFO   jTPCC : Term-00, Measured tpmTOTAL = 299.21
22:06:07,708 [Thread-2] INFO   jTPCC : Term-00, Session Start     = 2023-04-28 22:05:47
22:06:07,709 [Thread-2] INFO   jTPCC : Term-00, Session End       = 2023-04-28 22:06:07
22:06:07,709 [Thread-2] INFO   jTPCC : Term-00, Transaction Count = 100

注释:

  • tpmC(NewOrder) 每分钟139笔订单
  • tpmTOTAL 订单总数299笔
  • Transaction Count 执行20秒,执行了100笔订单(每分钟接近300笔订单)

清除压测数据

[root]# ./runDatabaseDestroy.sh postgres.props 
# ------------------------------------------------------------
# Loading SQL file ./sql.common/tableDrops.sql
# ------------------------------------------------------------
drop table bmsql_config;
drop table bmsql_new_order;
drop table bmsql_order_line;
drop table bmsql_oorder;
drop table bmsql_history;
drop table bmsql_customer;
drop table bmsql_stock;
drop table bmsql_item;
drop table bmsql_district;
drop table bmsql_warehouse;
drop sequence bmsql_hist_id_seq;

 

 

 

 

 

 

 

 

 

 

标签:INFO,Term,22,压测,数据库,00,benchmarksql,bmsql,id
From: https://www.cnblogs.com/haha029/p/17371480.html

相关文章

  • 京东物流常态化压测实践
    作者:京东物流王江波一、常态化压测建设目的为什么做常态化压测?目前面临主要问题,性能问题滞后发现,给大促带来不可控风险。目前日常需求频繁迭代,系统配置的变更、上下游依赖的变化、服务器资源置换等诸多因素均会对系统性能产生一定影响;日常很难做到对所有新项目或需求上线前后都进......
  • 《asyncio 系列》5. 基于 asyncio + SQLAlchemy 并发请求数据库
    楔子上一篇文章探讨了使用aiohttp库发出非阻塞Web请求,还讨论了使用几种不同的异步API来同时运行这些请求。通过结合asyncioAPI和aiohttp库,可以同时运行多个耗时的Web请求,从而提高应用程序的运行速度。但我们上一章学到的概念不仅适用于Web请求,也适用于运行SOL查......
  • postgresql有进程链接数据时删除数据库
    selectpg_terminate_backend(pg_stat_activity.pid)frompg_stat_activitywheredatname='数据库名称'andpid<>pg_backend_pid();命令解释:pg_terminate_backend:用来终止与数据库的连接的进程id的函数。pg_stat_activity:是一个系统表,用于存储服务进程的属性和状态。pg_......
  • 数据库基础问题?
    数据库是指按照一定的数据结构对大量数据进行存储和管理的系统。数据库系统是一个软件系统,用来管理和组织数据。它可以让用户方便地访问和处理数据,从而提高数据的使用效率和准确性。数据库系统的基础包括以下几个方面:数据库设计:数据库设计是指根据业务需求和数据特点,设计出适合......
  • 数据库基础问题?
    数据库是指按照一定的数据结构对大量数据进行存储和管理的系统。数据库系统是一个软件系统,用来管理和组织数据。它可以让用户方便地访问和处理数据,从而提高数据的使用效率和准确性。数据库系统的基础包括以下几个方面:数据库设计:数据库设计是指根据业务需求和数据特点,设计出适合业务......
  • mac 创建Mysql数据库
    一、安装Mysql1、在mac上可以使用homebrew来安装mysql,打开终端输入命令brewinstallmysql2、安装完成之后,需要启动mysql服务brewservicesstartmysql3、mysql服务启动后,可以登录mysqlmysql-uroot-p注意⚠️首次登录时,需要设置root用户密码二、创建新的数据库1......
  • linux 安装神州通用数据库 V7
    @目录操作系统、数据库1、官方下载链接2、windows客户端下载链接3、官方安装手册4、安装前准备3.1、创建安装用户3.2、以root用户修改神通数据库安装包的所有者为shentong用户3.3、以root用户创建神通数据库主目录并修改所有者为shentong用户3.4、以root用户临时修改init.d......
  • java基于springboot+vue非前后端分离的网上商城购物系统、在线商城管理系统,附源码+数
    1、项目介绍java基于springboot+vue非前后端分离的网上商城购物系统、在线商城管理系统,实现管理员:首页、个人中心、用户管理、商品分类管理、商品信息管理、订单评价管理、系统管理、订单管理,用户;首页、个人中心、订单评价管理、我的收藏管理、订单管理,前台首页;首页、商品信息、......
  • 举一个数据库死锁的例子,MySQL 怎么解决死锁?
    转载:https://juejin.cn/post/7072000882128191518分析&回答在数据库中有两种基本的锁类型:排它锁(ExclusiveLocks,即X锁)和共享锁(ShareLocks,即S锁)。当数据对象被加上排它锁时,其他的事务不能对它读取和修改。加了共享锁的数据对象可以被其他事务读取,但不能修改。数据库利用这两种基......
  • java基于springboot+vue非前后端分离的影城管理系统、影院销售管理系统,附源码+文档+PP
    1、项目介绍本影城管理系统主要包括二大功能模块,即用户功能模块和管理员功能模块。(1)管理员模块:系统中的核心用户是管理员,管理员登录后,通过管理员功能来管理后台系统。主要功能有:首页、个人中心、用户管理、电影类型管理、放映厅管理、电影信息管理、购票统计管理、系统管理、订......