Oracle 基准测试 SLOB(Silly Little OracleBenchmark)可以使用简单的数据库操作来模拟负载,然后根据分配给数据库的 SGA 大小,测试 CPU、内存(逻辑 I/O)和存储(物理 I/O)。该工具通过索引范围扫描和数据块查找来模拟整个过程。
SLOB 支持的测试类型具体如下
·支持 Oracle 逻辑读。 ·支持物理随机单块读取(按数据文件顺序读取)。 ·支持随机单块写入。 ·支持大量 redo 日志写入。
SLOB 下载地址为 https://kevinclosson.net/slob/。进行 SLOB 测试的前提条件具体如下。
进行 SLOB 测试的前提条件具体如下
·需要创建测试表空间,用于容纳SLOB初始化创建的对象。 ·运行初始化setup.sh,默认空间要求大小约为15GB。 ·将system用户密码修改为manager。
1.1、下载软件
代码语言:javascript复制https://kevinclosson.net/slob/
https://github.com/therealkevinc/SLOB_2.5.4.git
1.2、软件上传解压
代码语言:javascript复制MD5SUM:9105afd8de3c75c65b54141ece71203e 2021.05.12.slob_2.5.4.0.tar.gz
unzip SLOB_2.5.4-main.zip
cd SLOB_2.5.4-main/
tar -zxvf 2021.05.12.slob_2.5.4.0.tar.gz
cd SLOB/
pwd
/home/oracle/tmp/SLOB_2.5.4-main/SLOB
1.3、准备新建表空间 OLTP 和修改 system 用户密码
修改 system 密码为 manager,创建表空间 OLTP 大小 15GB。 然后运行初始化脚本的命令如下:
代码语言:javascript复制SQL> alter user system identified by manager;
SQL> create tablespace OLTP datafile ' DATA' size 15G;
1.4、初始化环境
代码语言:javascript复制$sh setup.sh OLTP 20
OLTP 是用于压力测试而创建的表空间名字,20 表示需要创建的用户数量(默认是128)然后便会创建 20 个用户和表数据。
代码语言:javascript复制NOTIFY : 2022.05.25-16:55:20 : Begin SLOB 2.5.4.0 setup.
NOTIFY : 2022.05.25-16:55:20 : ADMIN_CONNECT_STRING: "system/manager"
NOTIFY : 2022.05.25-16:55:20 : Load parameters from slob.conf:
SCALE: 80M (10240 blocks)
SCAN_TABLE_SZ: 1M (128 blocks)
LOAD_PARALLEL_DEGREE: 2
ADMIN_SQLNET_SERVICE: ""
SYSDBA_PASSWD: "manager"
DBA_PRIV_USER: "system"
Note: setup.sh will use the following connect strings as per slob.conf:
Admin Connect String: "system/manager"
Non-Admin Connect String: " "
NOTIFY : 2022.05.25-16:55:20 : Testing Admin connect using "sqlplus -L system/manager"
FATAL : 2022.05.25-16:55:21 : Cannot create tables in user-specified tablespace ("OLTP")
FATAL : 2022.05.25-16:55:21 : See /home/oracle/tmp/SLOB_2.5.4-main/SLOB/cr_tab_and_load.out
t4-rac19c-71:/home/oracle/tmp/SLOB_2.5.4-main/SLOB(jxrt4db1)$
t4-rac19c-71:/home/oracle/tmp/SLOB_2.5.4-main/SLOB(jxrt4db1)$ sh setup.sh OLTP 20
NOTIFY : 2022.05.25-16:59:03 : Begin SLOB 2.5.4.0 setup.
NOTIFY : 2022.05.25-16:59:03 : ADMIN_CONNECT_STRING: "system/manager"
NOTIFY : 2022.05.25-16:59:03 : Load parameters from slob.conf:
SCALE: 80M (10240 blocks)
SCAN_TABLE_SZ: 1M (128 blocks)
LOAD_PARALLEL_DEGREE: 2
ADMIN_SQLNET_SERVICE: ""
SYSDBA_PASSWD: "manager"
DBA_PRIV_USER: "system"
Note: setup.sh will use the following connect strings as per slob.conf:
Admin Connect String: "system/manager"
Non-Admin Connect String: " "
NOTIFY : 2022.05.25-16:59:03 : Testing Admin connect using "sqlplus -L system/manager"
NOTIFY : 2022.05.25-16:59:04 : Dropping prior SLOB schemas. This may take a while if there is a large number of old schemas.
NOTIFY : 2022.05.25-16:59:04 : Previous SLOB schemas have been removed
NOTIFY : 2022.05.25-16:59:04 : Preparing to load 20 schema(s) into tablespace: OLTP
NOTIFY : 2022.05.25-16:59:04 : Loading user1 schema
NOTIFY : 2022.05.25-16:59:11 : Finished loading and indexing user1 schema in 7 seconds
NOTIFY : 2022.05.25-16:59:11 : Commencing multiple, concurrent schema creation and loading
NOTIFY : 2022.05.25-16:59:11 : Waiting for background batch 1. Loading up to user3
NOTIFY : 2022.05.25-16:59:13 : Finished background batch 1. Loading and index creation complete : 2 seconds
NOTIFY : 2022.05.25-16:59:14 : Waiting for background batch 2. Loading up to user5
NOTIFY : 2022.05.25-16:59:15 : Finished background batch 2. Loading and index creation complete : 1 seconds
NOTIFY : 2022.05.25-16:59:16 : Waiting for background batch 3. Loading up to user7
NOTIFY : 2022.05.25-16:59:18 : Finished background batch 3. Loading and index creation complete : 2 seconds
NOTIFY : 2022.05.25-16:59:18 : Waiting for background batch 4. Loading up to user9
NOTIFY : 2022.05.25-16:59:20 : Finished background batch 4. Loading and index creation complete : 2 seconds
NOTIFY : 2022.05.25-16:59:20 : Waiting for background batch 5. Loading up to user11
NOTIFY : 2022.05.25-16:59:22 : Finished background batch 5. Loading and index creation complete : 2 seconds
NOTIFY : 2022.05.25-16:59:23 : Waiting for background batch 6. Loading up to user13
NOTIFY : 2022.05.25-16:59:24 : Finished background batch 6. Loading and index creation complete : 1 seconds
NOTIFY : 2022.05.25-16:59:25 : Waiting for background batch 7. Loading up to user15
NOTIFY : 2022.05.25-16:59:26 : Finished background batch 7. Loading and index creation complete : 1 seconds
NOTIFY : 2022.05.25-16:59:27 : Waiting for background batch 8. Loading up to user17
NOTIFY : 2022.05.25-16:59:29 : Finished background batch 8. Loading and index creation complete : 2 seconds
NOTIFY : 2022.05.25-16:59:29 : Waiting for background batch 9. Loading up to user19
NOTIFY : 2022.05.25-16:59:31 : Finished background batch 9. Loading and index creation complete : 2 seconds
NOTIFY : 2022.05.25-16:59:31 : Waiting for background batch 10. Loading up to user20
NOTIFY : 2022.05.25-16:59:33 : Finished background batch 10. Loading and index creation complete : 2 seconds
NOTIFY : 2022.05.25-16:59:33 : Completed concurrent data loading phase: 22 seconds
NOTIFY : 2022.05.25-16:59:33 : Creating SLOB UPDATE procedure
NOTIFY : 2022.05.25-16:59:34 : SLOB UPDATE procedure (./misc/procedure.sql) created.
NOTIFY : 2022.05.25-16:59:34 : Row and block counts for SLOB table(s) reported in ./slob_data_load_summary.txt
NOTIFY : 2022.05.25-16:59:34 : Please examine ./slob_data_load_summary.txt for any possible errors
NOTIFY : 2022.05.25-16:59:34 :
NOTIFY : 2022.05.25-16:59:34 : NOTE: No errors detected but if ./slob_data_load_summary.txt shows errors then
NOTIFY : 2022.05.25-16:59:34 : examine /home/oracle/tmp/SLOB_2.5.4-main/SLOB/cr_tab_and_load.out
NOTIFY : 2022.05.25-16:59:34 : SLOB setup complete. Total setup time: (31 seconds)
NOTIFY : 2022.05.25-16:59:34 : Please do not forget to compile the wait kit.
NOTIFY : 2022.05.25-16:59:34 : Please change directories to ./wait_kit and execute make(1).
NOTIFY : 2022.05.25-16:59:34 : Example:
NOTIFY : 2022.05.25-16:59:34 : $ cd ./wait_kit
NOTIFY : 2022.05.25-16:59:34 : $ make
根据提示编译工具包,命令如下:
代码语言:javascript复制cd ./wait_kit
make
rm -fr *.o mywait trigger create_sem
cc -c -o mywait.o mywait.c
cc -o mywait mywait.o
cc -c -o trigger.o trigger.c
cc -o trigger trigger.o
cc -c -o create_sem.o create_sem.c
cc -o create_sem create_sem.o
cp mywait trigger create_sem ../
rm -fr *.o
这里创建了user0-user20 共 21 个用户,每个用户下均有两张表 CF1、CF2,每张表有 10240 行,每个表有 20 列,ID 列为 NUMBER(15),其他列为 VARCHAR2(128) ,表上无任何索引。
代码语言:javascript复制select owner,table_name from dba_tables where owner like 'USER%' order by 1;
select USERNAME,ACCOUNT_STATUS,CREATED,DEFAULT_TABLESPACE from dba_users where account_status='OPEN' and username like 'USER%' order by CREATED asc;
select count(*) from user2.CF1;
COUNT(*)
----------
10240
SQL> desc user2.CF1;
Name Null? Type
----------------------------------------------------------------- -------- --------------------------------------------
CUSTID NUMBER(15)
C2 VARCHAR2(128)
C3 VARCHAR2(128)
C4 VARCHAR2(128)
C5 VARCHAR2(128)
C6 VARCHAR2(128)
C7 VARCHAR2(128)
C8 VARCHAR2(128)
C9 VARCHAR2(128)
C10 VARCHAR2(128)
C11 VARCHAR2(128)
C12 VARCHAR2(128)
C13 VARCHAR2(128)
C14 VARCHAR2(128)
C15 VARCHAR2(128)
C16 VARCHAR2(128)
C17 VARCHAR2(128)
C18 VARCHAR2(128)
C19 VARCHAR2(128)
C20 VARCHAR2(128)
默认情况下,setup.sh执行时应读取slob.conf配置文件。
1.5、修改 slob.conf 配置文件
runit.sh 脚本是性能测试驱动程序,默认情况下使用的是 slob.conf 中的参数设置,如果有需要,则可以使用命令行或直接修改 slob.conf 配置文件,重点参数列举如下。
·UPDATE_PCT=10:DML(Data ManipulationLanguage,数据操纵语言)占比,默认为10%。 ·SCALE=10000:数据加载大小,默认为 10000 block。 ·SCAN_TABLE_SZ=1M:单个测试表格的大小。 ·LOAD_PARALLEL_DEGREE=2:数据加载并发量。 ·RUN_TIME=300:测试时间,默认为 5min,超过时间会自动结束。
·DATABASE_STATISTICS_TYPE=awr :数据库统计报告,默认是 sp 报告,这里选择 awr。
可以根据不同的测试场景修改配置文件 slob.conf 的参数。
代码语言:javascript复制cat slob.conf | grep -v '^#'| grep -v '^$'
UPDATE_PCT=10
SCAN_PCT=0
RUN_TIME=300
WORK_LOOP=0
SCALE=10000 ---新版本这里设置80M会报错,默认是 10000 block
SCAN_TABLE_SZ=1M
WORK_UNIT=64
REDO_STRESS=LITE
LOAD_PARALLEL_DEGREE=2
THREADS_PER_SCHEMA=1
DATABASE_STATISTICS_TYPE=awr # Permitted values: [statspack|awr]
EXTERNAL_SCRIPT=""
DO_HOTSPOT=FALSE
HOTSPOT_MB=8
HOTSPOT_OFFSET_MB=16
HOTSPOT_FREQUENCY=3
HOT_SCHEMA_FREQUENCY=0
THINK_TM_FREQUENCY=0
THINK_TM_MIN=.1
THINK_TM_MAX=.5
1.6、SLOB 测试命令示例
SLOB执行测试的命令如下:
Single Option Invocation 单一选项调用
代码语言:javascript复制$ sh runit.sh <number-of-SLOB-schemas-to-test>
Multiple Option Invocation 多个选项调用
代码语言:javascript复制$ sh runit.sh -s <number-of-slob-schemas-to-test> -t <SLOB-threads-per-schema>
代码语言:javascript复制注意:单选项调用使用 slob.conf->THREADS_PER_SCHEMA。 如果你
在 SLOB.conf 中设置 THREADS_PER_SCHEMA,每个模式需要多个 SLOB 线程。
slob.conf->THREADS_PER_SCHEMA 的默认设置是 1。
使用多选项调用 slob.conf-> 覆盖 THREADS_PER_SCHEMA。
每个模式的 SLOB 线程数取自传递的参数与 -t 选项一起。
例子:
例1、256 个 SLOB 模式,每个模式带有 SLOB .conf->THREADS_PER_SCHEMA 编号
每个模式的 SLOB 线程数:
代码语言:javascript复制$ sh runit.sh 256
例2、16 个 SLOB 模式,每个模式有 32 个 SLOB 线程:
代码语言:javascript复制$ sh runit.sh -s 16 -t 32
注意:例 2 产生 512(16*32) 个 Oracle 数据库会话。更多详细信息请查看官方文档 ./SLOB_2.5.4-main/SLOB/doc/SLOB-2.5.0_README.pdf
1.7、模拟 512 个会话进行压测 5 分钟
代码语言:javascript复制$ sh runit.sh -s 16 -t 32
$ sh runit.sh -s 21 -t 30
代码语言:javascript复制$ sh runit.sh -s 16 -t 32
NOTIFY : 2022.05.25-18:31:23 : For security purposes all file and directory creation and deletions
NOTIFY : 2022.05.25-18:31:23 : performed by runit.sh are logged in: /home/oracle/tmp/SLOB_2.5.4-main/SLOB/.file_operations_audit_trail.out.
NOTIFY : 2022.05.25-18:31:23 : SLOB TEMPDIR is /tmp/.SLOB.2022.05.25.183123. SLOB will delete this directory at the end of this execution.
NOTIFY : 2022.05.25-18:31:23 : Sourcing in slob.conf
NOTIFY : 2022.05.25-18:31:23 : Performing initial slob.conf sanity check...
NOTIFY : 2022.05.25-18:31:23 :
NOTIFY : 2022.05.25-18:31:23 : SQLNET_SERVICE_BASE is not set. Users will connect via bequeth connections (not SQL*Net).
NOTIFY : 2022.05.25-18:31:23 : Connecting to the instance to validate slob.conf->SCALE setting.
UPDATE_PCT: 10
SCAN_PCT: 0
RUN_TIME: 300
WORK_LOOP: 0
SCALE: 10000 (10000 blocks)
WORK_UNIT: 64
REDO_STRESS: LITE
HOT_SCHEMA_FREQUENCY: 0
HOTSPOT_MB: 8
HOTSPOT_OFFSET_MB: 16
HOTSPOT_FREQUENCY: 3
THINK_TM_FREQUENCY: 0
THINK_TM_MIN: .1
THINK_TM_MAX: .5
DATABASE_STATISTICS_TYPE: awr
SYSDBA_PASSWD: "manager"
DBA_PRIV_USER: "system"
ADMIN_SQLNET_SERVICE: ""
SQLNET_SERVICE_BASE: ""
SQLNET_SERVICE_MAX: ""
EXTERNAL_SCRIPT: ""
THREADS_PER_SCHEMA: 32 (-t option)
Note: runit.sh will use the following connect strings as per slob.conf settings:
Admin Connect String: "system/manager"
NOTIFY : 2022.05.25-18:31:24 : Clearing temporary SLOB output files from previous SLOB testing.
NOTIFY : 2022.05.25-18:31:24 : Testing admin connectivity to the instance to validate slob.conf settings.
NOTIFY : 2022.05.25-18:31:24 : Testing connectivity. Command: "sqlplus -L system/manager".
NOTIFY : 2022.05.25-18:31:25 : Next, testing 16 user (non-admin) connections...
NOTIFY : 2022.05.25-18:31:25 : Testing connectivity. Command: "sqlplus -L user1/user1".
NOTIFY : 2022.05.25-18:31:25 : Testing connectivity. Command: "sqlplus -L user16/user16".
NOTIFY : 2022.05.25-18:31:25 : Performing redo log switch.
NOTIFY : 2022.05.25-18:31:25 : Redo log switch complete. Setting up trigger mechanism.
NOTIFY : 2022.05.25-18:31:35 : Running iostat, vmstat and mpstat on current host--in background.
NOTIFY : 2022.05.25-18:31:35 : Connecting 32 (THREADS_PER_SCHEMA) session(s) to 16 schema(s) ...
NOTIFY : 2022.05.25-18:31:43 : Saved pids of monitored sqlplus processes in: /tmp/.SLOB.2022.05.25.183123/sqlplus_pids.txt
NOTIFY : 2022.05.25-18:31:43 : Pausing for 2 seconds before triggering the test.
NOTIFY : 2022.05.25-18:31:46 : Executing awr "before snap" procedure. Command: "sqlplus -S -L system/manager".
NOTIFY : 2022.05.25-18:31:54 : Before awr snap ID is 293
NOTIFY : 2022.05.25-18:31:54 : Test has been triggered.
NOTIFY : 2022.05.25-18:32:19 : Waiting for 290 seconds before monitoring running processes (for exit).
NOTIFY : 2022.05.25-18:37:09 : Entering process monitoring loop.
NOTIFY : 2022.05.25-18:37:19 : There are 509 sqlplus processes remaining.
NOTIFY : 2022.05.25-18:37:29 : There are 267 sqlplus processes remaining.
NOTIFY : 2022.05.25-18:37:39 : There are 135 sqlplus processes remaining.
NOTIFY : 2022.05.25-18:37:46 : Run time 352 seconds.
NOTIFY : 2022.05.25-18:37:47 : Executing awr "after snap" procedure. Command: "sqlplus -S -L system/manager".
NOTIFY : 2022.05.25-18:37:59 : After awr snap ID is 294
NOTIFY : 2022.05.25-18:37:59 : Terminating background data collectors.
runit.sh: line 1548: 24519 Killed ( mpstat -P ALL 3 > mpstat.out 2>&1 )
runit.sh: line 1548: 24517 Killed ( iostat -t -xm 3 > iostat.out 2>&1 )
runit.sh: line 1548: 24518 Killed ( vmstat -t 3 > vmstat.out 2>&1 )
NOTIFY : 2022.05.25-18:38:33 :
NOTIFY : 2022.05.25-18:38:33 : SLOB test is complete.
NOTIFY : 2022.05.25-18:38:33 : Cleaning up SLOB temporary directory (/tmp/.SLOB.2022.05.25.183123).
压测期间 Top 命令截图
$ sh runit.sh -s 20 -t 30 如下是使用 600 个并发会话压测 30 分钟的 top 截图。
SLOB 执行前会创建快照点,如上述代码段所示。293、294 为我本次的快照点,结束后会在当前目录下生成 I/O 的测试结果信息 awr.html.gz、awr_rac.html.gz、mpstat.out、iostat.out 和 vmstat.out。
解压 awr 报告下载到本地查看相关信息。
代码语言:javascript复制gunzip awr.html.gz
gunzip awr.html.gz
-------------------------------------------------------------------------------
-rw-r--r-- 1 oracle oinstall 1665720 May 25 18:46 awr.html
-rw-r--r-- 1 oracle oinstall 423815 May 25 18:46 awr.txt
-rw-r--r-- 1 oracle oinstall 1415483 May 25 18:46 awr_rac.html
-rw-r--r-- 1 oracle oinstall 344105 May 25 18:46 awr_rac.txt
-rw-r--r-- 1 oracle oinstall 204399 May 25 18:46 iostat.out
-rw-r--r-- 1 oracle oinstall 123388 May 25 18:47 mpstat.out
-rw-r--r-- 1 oracle oinstall 7 May 25 18:46 tm.out
-rw-r--r-- 1 oracle oinstall 15239 May 25 18:47 vmstat.out
-------------------------------------------------------------------------------
awr 截图
iostat 截图
vmstat 截图
mpstat 截图
1.8、脚本执行期间的错误
错误1:
代码语言:javascript复制FATAL : 2022.05.25-17:23:25 : The value assigned to slob.conf->SCALE (80M [5120]) is an illegal value.
FATAL : 2022.05.25-17:23:25 : Illegal SCALE value. Mininum supported value is 10000 blocks.
解决办法:修改 slob.conf 配置文件中 SCALE 的值为 10000
错误2:
代码语言:javascript复制ERROR:ORA-00020: maximum number of processes (640) exceeded
解决办法:最大连接数默认 640,一下子就压到 640 导致超了最大连接数,修改数据库最大连接数为 2000 并重启数据库。
错误3:
代码语言:javascript复制FATAL : 2022.05.25-17:35:33 : f_snap_database_stats: EXEC PERFSTAT.STATSPACK.SNAP failed. Error output follows:
:SNAP := STATSPACK.SNAP;
*
ERROR at line 2:
ORA-06550: line 2, column 11:
PLS-00201: identifier 'STATSPACK.SNAP' must be declared
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored
解决办法:slob.conf 参数使用了默认生成 statspack 报告,修改 slob.conf 配置文件参数为 DATABASE_STATISTICS_TYPE=awr,让其生成 AWR 报告即可。
好了,本次就先这样吧,swingbench 等其他工具有机会在尝试吧,欢迎一起来讨论。全文完,希望可以帮到正在阅读的你,如果觉得有帮助,可以分享给你身边的朋友,同事,你关心谁就分享给谁,一起学习共同进步~~~