数据库测试神器==>YCSB
简单介绍
YCSB, 英文全称:Yahoo! Cloud Serving Benchmark (YCSB) 。是 Yahoo 公司的一个用来对云服务进行基础测试的工具, 目标是促进新一代云数据服务系统的性能比较。由于它集成了大多数常用的数据库的测试代码,所以,它也是数据库测试的一大利器.
项目Github地址: YCSB
文中部分资料翻译自:https://github.com/brianfrankcooper/YCSB/wiki
配置YCSB环境
Java
- 到 Oracle 下载相应的Java版本
- 或者直接用 apt-get 下载, 教程Nutao-Ubuntu 安装java
- 验证JAVA是否安装成功 java -version:
1 | $ java -version |
Maven
- 到国内开源镜像下载Maven, 推荐使用TUNA-清华开源镜像站
- 配置Maven
1 | # 解压 |
- 追加
1 | #Maven_home |
- 然后 Source
1 | source /etc/profile |
- 注销或重启后生效( 不重启在当前Shell 下生效)
1 | # 验证 |
下载YCSB
目前最新的稳定版本是 0.12.0 (下载特别慢, 最好是挂VPN或者用云服务器下载)
1 | curl -O --location https://github.com/brianfrankcooper/YCSB/releases/download/0.12.0/ycsb-0.12.0.tar.gz |
或者直接在Github上克隆 (编译巨慢, 要下很多的包)
1 | git clone git://github.com/brianfrankcooper/YCSB.git |
编译的命令参考其项目Readme.每一个组件都可以单独编译,相当良心。
测试是否安装成功
1 | ./bin/ycsb |
测试
编写Workload(这部分英文比较简单,将就看看吧)
Core YCSB properties
- workload: workload class to use (e.g. com.yahoo.ycsb.workloads.CoreWorkload)
- db: database class to use. Alternatively this may be specified on the command line. (default: com.yahoo.ycsb.BasicDB)
- exporter: measurements exporter class to use (default: com.yahoo.ycsb.measurements.exporter.TextMeasurementsExporter)
- exportfile: path to a file where output should be written instead of to stdout (default: undefined/write to stdout)
- threadcount: number of YCSB client threads. Alternatively this may be specified on the command line. (default: 1)
- measurementtype: supported measurement types are histogram and timeseries (default: histogram)
Core workload package properties
- fieldcount: the number of fields in a record (default: 10)
- fieldlength: the size of each field (default: 100)
- readallfields: should reads read all fields (true) or just one (false) (default: true)
- readproportion: what proportion of operations should be reads (default: 0.95)
- updateproportion: what proportion of operations should be updates (default: 0.05)
- insertproportion: what proportion of operations should be inserts (default: 0)
- scanproportion: what proportion of operations should be scans (default: 0)
- readmodifywriteproportion: what proportion of operations should be read a record, modify it, write it back (default: 0)
- requestdistribution: what distribution should be used to select the records to operate on – uniform, zipfian or latest (default: uniform)
- maxscanlength: for scans, what is the maximum number of records to scan (default: 1000)
- scanlengthdistribution: for scans, what distribution should be used to choose the number of records to scan, for each scan, between 1 and maxscanlength (default: uniform)
- insertorder: should records be inserted in order by key (“ordered”), or in hashed order (“hashed”) (default: hashed)
- operationcount: number of operations to perform.
- maxexecutiontime: maximum execution time in seconds. The benchmark runs until either the operation count has exhausted or the maximum specified time has elapsed, whichever is earlier.
- table: the name of the table (default: usertable)
- recordcount: number of records to load into the database initially (default: 0)
- core_workload_insertion_retry_limit: number of attempts for any failed insert operation (default: 0)
- core_workload_insertion_retry_interval: interval between retries, in seconds (default: 3)
MongoDB的 workload模板
1 | # 记录数 |
执行测试
1 | # 可以通过此命令查看ycsb的参数 |
shell命令
1 | ./bin/ycsb load mongodb-async -s -threads 20 -P workloads/mongodb/b > out |
- -s 代表输出status
- -threads 指定线程数
- -P 指定workload
- > 代表stdout 输出到 out 文件
测试结果输出
1 | cisdi@master:~/Downloads/ycsb-0.12.0$ cat out |