上一篇介绍了,如何安装支持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