sysbench for oracle database (使用篇)

上一篇介绍了,如何安装支持oracle的sysbench,这次我们看下如何使用sysbench对oracle数据库进行基本压测。

首先可以看到sysbench的帮助信息中,关于数据库的参数信息:

General database options:

--db-driver=STRING specifies database driver to use ('help' to get list of available drivers)

--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]

--db-debug=[on|off] print database-specific debug information [off]

Compiled-in database drivers:

oracle - Oracle driver

oracle options:

--oracle-user=STRING Oracle user [sbtest]

--oracle-password=STRING Oracle password []

--oracle-db=STRING Oracle database name [sbtest]

其实我们可以从sysbench自带的lua脚本common.lua中,能看到更多的配置项。如在我的机器上,是在/usr/local/sysbench/share/sysbench/common.lua里,可以看到更多设置参数:

function set_vars()
	oltp_table_size = oltp_table_size or 10000
	oltp_range_size = oltp_range_size or 100
	oltp_tables_count = oltp_tables_count or 1
	oltp_point_selects = oltp_point_selects or 10
	oltp_simple_ranges = oltp_simple_ranges or 1
	oltp_sum_ranges = oltp_sum_ranges or 1
	oltp_order_ranges = oltp_order_ranges or 1
	oltp_distinct_ranges = oltp_distinct_ranges or 1
	oltp_index_updates = oltp_index_updates or 1
	oltp_non_index_updates = oltp_non_index_updates or 1

	if (oltp_auto_inc == 'off') then
		oltp_auto_inc = false
	else
		oltp_auto_inc = true
	end

	if (oltp_read_only == 'on') then
		oltp_read_only = true
	else
		oltp_read_only = false
	end

	if (oltp_skip_trx == 'on') then
		oltp_skip_trx = true
	else
		oltp_skip_trx = false
	end

end

oltp_table_size 为数据表行数,oltp_tables_count 为要操作几张表等等,读者可以自行阅读该lua脚本。

 

1、准备阶段

[root@rac2 sysbench]# sysbench --test=oltp --db-driver=oracle --oltp-table-name=sysbench --oltp_tables_count=8 --oltp-table-size=1000000 --oracle-db=ora19c --oracle-user=sysbench --oracle-password=sysbench prepare

sysbench 0.5: multi-threaded system evaluation benchmark



Creating table 'sbtest1'...

Inserting 100000 records into 'sbtest1'

Inserting 100000 records into 'sbtest2'

Inserting 100000 records into 'sbtest3'

Inserting 100000 records into 'sbtest4'

Inserting 100000 records into 'sbtest5'

Inserting 100000 records into 'sbtest6'

Inserting 100000 records into 'sbtest7'

Inserting 100000 records into 'sbtest8'

此时,我设置了oltp_table_size为100w,oltp_tables_count为8,即往数据库插入8张表,每张表100w条数据,其中oracle-db为实例名。

如果不幸出现 Unknown database driver: oracle 错误,该错误为lua脚本报的,需要替换lua脚本,这里下载https://github.com/osdba/sysbench_lua

解压后,将里面的lua文件全部替换到/usr/local/sysbench/share/sysbench/中,再执行就好了。

我故意写了oltp.lua的路径,可以看到lua脚本默认路径在/usr/local/sysbench/share/sysbench/。

 

2、运行

sysbench --test=/home/oracle/sysbench/tests/db/lua/oltp.lua  --db-driver=oracle --oltp-table-name=sysbench --oltp-table-size=1000000 --oltp-tables-count=10 --oracle-db=oradb --oracle-user=sysbench --oracle-password=XXXX --max-time=900 --max-requests=10000000 --num-threads=40 --report-interval=10 run

我机器执行run时,sysbench遇到了段错误,暂时没看问题原因。

 

3、清理数据

[root@rac2 ~]# sysbench --test=/usr/local/sysbench/share/sysbench/oltp.lua --db-driver=oracle --oltp-table-name=sysbench --oltp_tables_count=8 --oltp-table-size=100000 --oracle-db=ora19c --oracle-user=sysbench --oracle-password=sysbench cleanup
sysbench 0.5: multi-threaded system evaluation benchmark

Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
Dropping table 'sbtest3'...
Dropping table 'sbtest4'...
Dropping table 'sbtest5'...
Dropping table 'sbtest6'...
Dropping table 'sbtest7'...
Dropping table 'sbtest8'...

sysbench的其它的对于系统的基准测试,比如压测cpu、memory、thread、mutex、fileio等的命令,可以自行谷歌下,有很多资料,也可以打 sysbench --help 查看帮助信息来使用,或者使用官方文档https://github.com/akopytov/sysbench/说明。

比如我测的命令如下:

sysbench --test=cpu help
sysbench --test=cpu --cpu-max-prime=200000 run
sysbench --test=cpu --cpu-max-prime=500000 --max-requests=200 run


sysbench --test=memory help
sysbench --test=memory --memory-block-size=8k --memory-total-size=100G --memory-access-mode=seq run
sysbench --test=memory --threads=60 --memory-block-size=8k --memory-total-size=100G --memory-access-mode=rnd run


sysbench --test=fileio --file-num=2048 --file-block-size=32K --file-total-size=5G --file-test-mode=rndrw  prepare
sysbench --test=fileio --file-num=2048 --file-block-size=32K --file-total-size=5G --file-test-mode=rndrw run
sysbench --test=fileio --file-num=2048 --file-block-size=32K --file-total-size=5G --file-test-mode=rndrw cleanup


sysbench --test=mutex --mutex-num=4096 --mutex-locks=50000 --mutex-loops=2000000 run 


sysbench --num-threads=264 --test=threads --thread-yields=60 --thread-locks=22 run

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
你可以使用 Sysbench 工具来进行 Oracle 数据库的压力测试。Sysbench 是一个开源的基准测试工具,它可以模拟多种负载类型,包括 OLTP(联机事务处理)工作负载,适用于测试数据库的性能。 在使用 Sysbench 进行 Oracle 压力测试之前,你需要安装 Sysbench 工具和配置 Oracle 数据库的连接信息。以下是一些基本步骤: 1. 安装 Sysbench 工具:根据你的操作系统,从 Sysbench 官方网站下载并安装 Sysbench 工具。 2. 配置 Oracle 数据库连接信息:在 Sysbench 的配置文件中,你需要提供 Oracle 数据库的连接信息,包括主机名、端口号、用户名、密码等。可以根据你的需求进行相应的配置。 3. 创建测试表:在 Oracle 数据库中创建一个用于测试的表,可以使用 Sysbench 提供的脚本来创建。 4. 运行压力测试:使用 Sysbench 命令来运行压力测试。例如,以下命令可以运行一个 OLTP 类型的压力测试: ``` sysbench --db-driver=oracle --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=60 --report-interval=10 oltp_read_only run ``` 这个命令将模拟 10 个线程同时访问 10 张表,并持续运行 60 秒,每隔 10 秒输出一次报告。 5. 分析结果:压力测试运行结束后,你可以分析 Sysbench 生成的报告,查看数据库的性能指标,如每秒事务数(TPS)、平均响应时间等。根据需要可以调整测试参数,进一步优化数据库性能。 请注意,以上步骤仅为简要介绍,实际操作可能需要根据你的具体环境和需求进行适当调整。建议参考 SysbenchOracle 文档获取更详细的信息和指导。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值