sysbench memory --threads=12 --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run Running the test with following options: Number of threads: 12 Initializing random number generator from current time Running memory speed test with the following options: block size: 8KiB total size: 102400MiB operation: write scope: global Initializing worker threads... Threads started! Total operations: 13107192 (1684079.88 per second) 102399.94 MiB transferred (13156.87 MiB/sec) General statistics: total time: 7.7816s total number of events: 13107192 Latency (ms): min: 0.00 avg: 0.01 max: 139.09 95th percentile: 0.00 sum: 68748.61 Threads fairness: events (avg/stddev): 1092266.0000/0.00 execution time (avg/stddev): 5.7291/1.08
sysbench memory --threads=12 --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run Running the test with following options: Number of threads: 12 Initializing random number generator from current time Running memory speed test with the following options: block size: 8KiB total size: 102400MiB operation: write scope: global Initializing worker threads... Threads started! Total operations: 3099810 (309929.69 per second) 24217.27 MiB transferred (2421.33 MiB/sec) General statistics: total time: 10.0002s total number of events: 3099810 Latency (ms): min: 0.00 avg: 0.04 max: 95.04 95th percentile: 0.01 sum: 116396.55 Threads fairness: events (avg/stddev): 258317.5000/22378.41 execution time (avg/stddev): 9.6997/0.09
Running the test with following options: Number of threads: 16 Initializing random number generator from current time Extra file open flags: directio 16 files, 128MiB each 2GiB total file size Block size 16KiB Number of IO requests: 0 Read/Write ratio for combined random IO test: 1.50 Calling fsync() at the end of test, Enabled. Using synchronous I/O mode Doing random read test Initializing worker threads... Threads started! File operations: reads/s: 2291.53 writes/s: 0.00 fsyncs/s: 0.00 Throughput: read, MiB/s: 35.81 written, MiB/s: 0.00 General statistics: total time: 180.0079s total number of events: 412498 Latency (ms): min: 0.10 avg: 6.98 max: 49.85 95th percentile: 9.91 sum: 2879915.11 Threads fairness: events (avg/stddev): 25781.1250/46.71 execution time (avg/stddev): 179.9947/0.00
多线程调度基准测试
1 2 3 4 5
sysbench --test=mutex help mutex options: --mutex-num=N total size of mutex array [4096] --mutex-locks=N number of mutex locks to do per thread [50000] --mutex-loops=N number of empty loops to do outside mutex lock [10000]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
sysbench mutex --threads=8 --mutex-num=2000 --mutex-locks=10000 --mutex-loops=5000 run Running the test with following options: Number of threads: 8 Initializing random number generator from current time Initializing worker threads... Threads started! General statistics: total time: 0.1319s total number of events: 8 Latency (ms): min: 33.03 avg: 98.79 max: 128.91 95th percentile: 127.81 sum: 790.31 Threads fairness: events (avg/stddev): 1.0000/0.00 execution time (avg/stddev): 0.0988/0.03
POST多线程基准测试
1 2 3 4 5
sysbench --test=threads help threads options: --threads=N 开启线程数量 --thread-yields=N number of yields to do per request [1000] --thread-locks=N number of locks per thread [8]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
sysbench threads --threads=8 --thread-yields=200 --thread-locks=2 run Running the test with following options: Number of threads: 8 Initializing random number generator from current time Initializing worker threads... Threads started! General statistics: total time: 10.0018s total number of events: 30114 Latency (ms): min: 0.16 avg: 2.66 max: 239.52 95th percentile: 7.56 sum: 79992.02 Threads fairness: events (avg/stddev): 3764.2500/200.20 execution time (avg/stddev): 9.9990/0.00
#point_selects:主键等值查询 SELECT c FROM sbtest%u WHERE id=? #simple_ranges:简单范围查询(主键range) SELECT c FROM sbtest%u WHERE id BETWEEN ? AND ? #sum_ranges:范围求和(简单范围查询的基础上做sum) SELECTSUM(k) FROM sbtest%u WHERE id BETWEEN ? AND ? #order_ranges:简单范围查询(主键range的基础上做排序) SELECT c FROM sbtest%u WHERE id BETWEEN ? AND ? ORDERBY c #distinct_ranges:去重范围查询(主键range+ 排序 + 去重) SELECTDISTINCT c FROM sbtest%u WHERE id BETWEEN ? AND ? ORDERBY c #index_updates:索引更新操作 UPDATE sbtest%u SET k=k+1WHERE id=? #non_index_updates:非索引更新 UPDATE sbtest%u SET c=? WHERE id=? #deletes:删除操作 DELETEFROM sbtest%u WHERE id=? #inserts:插入操作 INSERTINTO sbtest%u (id, k, c, pad) VALUES (?, ?, ?, ?)
-- 初始化 functioninit() -- 创建表结构,获取c,pad字段随机字符串,插入数据,建立二级索引 functioncreate_table(drv, con, table_num) -- 创建表结构,表结构如下 -- CREATE TABLE `sbtest1` ( -- `id` int(11) NOT NULL AUTO_INCREMENT, # 主键 -- `k` int(11) NOT NULL DEFAULT '0', # 二级索引 -- `c` char(120) NOT NULL DEFAULT '', -- `pad` char(60) NOT NULL DEFAULT '', -- PRIMARY KEY (`id`), -- KEY `k_1` (`k`) -- ) ENGINE=InnoDB AUTO_INCREMENT=1000001 DEFAULT CHARSET=latin1 -- get_c_value() 获取字段c的值 -- get_pad_value() 获取字段pad的值 -- INSERT 语句插入到相关表,直到达到指定的table-size -- 建立二级索引k -- 获取字段c的值,返回一个随机字符串 functionget_c_value() -- 获取字段pad的值,返回一个随机字符串 functionget_pad_value() -- 初始化线程 functionthread_init() -- 关闭线程连接 functionthread_done() -- Close prepared statements functionclose_statements() -- 如果我们已经重新连接了,那么重新准备语句, functionsysbench.hooks.before_restart_event(errdesc) -- close_statements() //Close prepared statements -- prepare_statements() // This function is a 'callback' defined by individual benchmark scripts -- 构造语句 functionprepare_for_each_table(key) -- 对应prepare命令 functioncmd_prepare() -- 对应prewarm命令 functioncmd_prewarm() -- 清理数据,把相关表都DROP掉 functioncleanup() -- 启动事务 BEGIN functionprepare_begin() //构造 BEGIN 语句 functionbegin() //执行 BEGIN 语句 -- 提交事务 COMMIT functionprepare_commit() //构造 BEGIN 语句 functioncommit() //执行 COMMIT 语句 -- 主键等值查询 SELECT c FROM sbtest? WHERE id = ? function prepare_point_selects() // 调用 prepare_for_each_table() 函数生成ponit_selects语句 function execute_point_selects() // 执行 prepare_point_selects() 生成的语句 -- 主键范围查询 SELECT c FROM sbtest? WHERE id BETWEEN ? AND ? functionprepare_simple_ranges() // 调用 prepare_for_each_table() 函数生成simple_ranges语句 functionexecute_simple_ranges() // 执行 prepare_point_selects() 生成的语句 -- 主键范围查询 + 求和 SELECT SUM(k) FROM sbtest? WHERE id BETWEEN ? AND ? functionprepare_sum_ranges() // 调用 prepare_for_each_table() 函数生成sum_ranges语句 functionexecute_sum_ranges() // 执行 prepare_point_selects() 生成的语句 -- 主键范围查询 + 排序 SELECT c FROM sbtest%u WHERE id BETWEEN ? AND ? ORDER BY c function prepare_order_ranges() functionexecute_order_ranges() -- 主键范围查询 + 排序 + 去重 SELECT DISTINCT c FROM sbtest%u WHERE id BETWEEN ? AND ? ORDER BY c functionprepare_distinct_ranges() functionexecute_distinct_ranges() -- 二级索引上更新(k是二级索引) UPDATE sbtest%u SET k=k+1 WHERE id=? function prepare_index_updates() // 调用 prepare_for_each_table() 函数生成index_updates语句 function execute_index_updates() // 执行 prepare_point_selects() 生成的语句 -- 无索引的更新 UPDATE sbtest%u SET c=? WHERE id=? function prepare_non_index_updates() functionexecute_non_index_updates() -- 删除 DELETE FROM sbtest%u WHERE id=? functionprepare_delete_inserts()functionexecute_delete_inserts() // 执行 prepare_for_each_table 生成的语句
读写测试的语句格式如下(定义在stmt_defs变量中)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
--point_selects:主键等值查询 SELECT c FROM sbtest%u WHERE id=? -- simple_ranges:简单范围查询(主键range) SELECT c FROM sbtest%u WHERE id BETWEEN ? AND ? -- sum_ranges:范围求和(简单范围查询的基础上做sum) SELECT SUM(k) FROM sbtest%u WHERE id BETWEEN ? AND ? -- order_ranges:简单范围查询(主键range的基础上做排序) SELECT c FROM sbtest%u WHERE id BETWEEN ? AND ? ORDER BY c -- distinct_ranges:去重范围查询(主键range + 排序 + 去重) SELECT DISTINCT c FROM sbtest%u WHERE id BETWEEN ? AND ? ORDER BY c -- index_updates:索引更新操作 UPDATE sbtest%u SET k=k+1 WHERE id=? -- non_index_updates:非索引更新 UPDATE sbtest%u SET c=? WHERE id=? -- deletes:删除操作 DELETE FROM sbtest%u WHERE id=? -- inserts:插入操作 INSERT INTO sbtest%u (id, k, c, pad) VALUES (?, ?, ?, ?)
bulk_insert.lua 插入的lua脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14
-- 初始化线程 functionthread_init() -- 准备表结构 prepare() -- CREATE TABLE IF NOT EXISTS sbtest%d ( -- id INTEGER NOT NULL, -- k INTEGER DEFAULT '0' NOT NULL, -- PRIMARY KEY (id))]], i)) -- 批量插入 event() -- 关闭线程 thread_done(thread_9d) -- 清理数据,DROP掉相关的表 cleanup()