1、 bulk_insert.lua 批量写入操作
2、 oltp_common.lua oltp公用代码
3、 oltp_delete.lua 写入和删除并行操作
4、 oltp_insert.lua 纯写入操作
5、 oltp_point_select.lua 只读操作,条件为唯一索引列
6、 oltp_read_only.lua 只读操作,包含聚合,去重等操作
7、 oltp_read_write.lua 读写混合操作,最常用的脚本
8、 oltp_update_index.lua 更新操作,通过主键进行更新
9、 oltp_update_non_index.lua 更新操作,不通过索引列
10、 oltp_write_only.lua 纯写操作,常用脚本,包括insert update delete
11、 select_random_points.lua 随机集合只读操作,常用脚本,聚集索引列的selete in操作
12、 select_random_ranges.lua 随机范围只读操作,常用脚本,聚集索引列的selete between操作
-–db-driver:用到的数据库类型
-–mysql-host:数据库的IP
-–mysql-port:数据库的端口
-–mysql-socket:socket的路径
-–mysql-user:数据库用户名
-–mysql-password:用户密码
-–mysql-db:数据库名字,默认为sysbench,需要提前创建创好
-–tables:生成表的个数
-–table-size:每个表的行数
-–report-interval:每隔多久在屏幕打印一次信息
-–time:压测时间
-–threads:启动多少个线程,即模拟多少个用户
oltp_read_write.lua options:
--auto_inc[=on|off] Use AUTO_INCREMENT column as Primary Key (for MySQL), or its alternatives in other DBMS. When disabled, use client-generated IDs [on]
--create_secondary[=on|off] Create a secondary index in addition to the PRIMARY KEY [on]
--delete_inserts=N Number of DELETE/INSERT combinations per transaction [1]
--distinct_ranges=N Number of SELECT DISTINCT queries per transaction [1]
--index_updates=N Number of UPDATE index queries per transaction [1]
--mysql_storage_engine=STRING Storage engine, if MySQL is used [innodb]
--non_index_updates=N Number of UPDATE non-index queries per transaction [1]
--order_ranges=N Number of SELECT ORDER BY queries per transaction [1]
--pgsql_variant=STRING Use this PostgreSQL variant when running with the PostgreSQL driver. The only currently supported variant is 'redshift'. When enabled, create_secondary is automatically disabled, and delete_inserts is set to 0
--point_selects=N Number of point SELECT queries per transaction [10]
--range_selects[=on|off] Enable/disable all range SELECT queries [on]
--range_size=N Range size for range SELECT queries [100]
--secondary[=on|off] Use a secondary index in place of the PRIMARY KEY [off]
--simple_ranges=N Number of simple range SELECT queries per transaction [1]
--skip_trx[=on|off] Don't start explicit transactions and execute all queries in the AUTOCOMMIT mode [off]
--sum_ranges=N Number of SELECT SUM() queries per transaction [1]
--table_size=N Number of rows per table [10000]
--tables=N Number of tables [1]
mysql -uroot -p123 -e "create database sbtest;" -- 创建测试数据库
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --threads=4 prepare
登录数据库检查生成表和数据情况
情况1:查询
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --report-interval=10 --threads=128 --time=600 ru
备注:重要指标
QPS(Query per second) 每秒查询量:21021.78
TPS(Transaction per second)每秒事务量 1052.19
情况2:在每个查询的事物里面添加 INSERT/UPDATE/DELDETE 操作
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --delete_inserts=10 --index_updates=10 --non_index_updates=10 --report-interval=10 --threads=4 --time=60 run
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --delete_inserts=10 --index_updates=10 --non_index_updates=10 --report-interval=10 --threads=4 --time=60 cleanup