教程,使用YCSB测试MYSQL数据库,获取千万条测试后的数据

Yahoo! Cloud Serving Benchmark (YCSB)是一个数据库特别是nosql数据库性能测试的benchmark。在GitHub中有3.9千个star和1.9千个forks。本文讲解如何使用YCSB测试MYSQL数据库的性能。

本人最终的结果是获取测试之后保存在MYSQL中的数据,需要10000000条记录。这个过程包含性能测试的步骤。

系统:Windows 10; MYSQL5.7

  1. 安装MYSQL数据库,(测试能够登录进去)。
  2. 创建库和table。根据这个链接 https://github.com/brianfrankcooper/YCSB/tree/master/jdbc,我们使用下面的命令创建一个表,这个表只有两个字段。
CREATE TABLE usertable (
	YCSB_KEY VARCHAR(255) PRIMARY KEY,
	FIELD0 TEXT
);
  1. 下载YCSB,https://github.com/brianfrankcooper/YCSB/releases/download/0.17.0/ycsb-0.17.0.tar.gz, 该链接是从YCSB的github主页(https://github.com/brianfrankcooper/YCSB)中copy的。
  2. 解压YCSB的包,使用CMD进入解压包的目录
  3. 修改ycsb-0.17.0\jdbc-binding\conf\db.properties ,用于YCSB连接本地的MYSQL数据库。
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://127.0.0.1:3306/ycsb
db.user=root
db.passwd=xxx

其中ycsb是数据库名,根据自己的实际情况修改。

  1. 修改workload文件。该文件说明了如何测试数据库的性能,比如插入多少条数据,读取百分之几的数据。下载的YCSB包中的目录ycsb-0.17.0\workloads下有几个样本。这里本人根据所提供的样本得到自己的workload文件。该文件只写入数据。

# There is no default setting for recordcount but it is
# required to be set.
# The number of records in the table to be inserted in
# the load phase or the number of records already in the 
# table before the run phase.
recordcount=10000000

# There is no default setting for operationcount but it is
# required to be set.
# The number of operations to use during the run phase.
operationcount=10000000

workload=site.ycsb.workloads.CoreWorkload

readallfields=true

readproportion=0
updateproportion=0
scanproportion=0
insertproportion=0

# The name of the database table to run queries against
table=usertableuniform

# The number of fields in a record
fieldcount=1

# The distribution of requests across the keyspace
#requestdistribution=zipfian
requestdistribution=uniform
#requestdistribution=latest

# Should records be inserted in order or pseudo-randomly
#insertorder=hashed
insertorder=ordered
  1. 将JDBC driver放到jdbc-binding/lib目录下。jdbc的驱动用于连接MYSQL数据库。
  2. 如果是在Windows中,打开cmd窗口,进入YCSB解压包所在的目录(如下),输入下面命令即可开始测试。
C:\Users\liang\Downloads\ycsb-0.17.0\ycsb-0.17.0\bin>ycsb.bat load jdbc -P ../workloads/myworkload -P ../jdbc-binding/conf/db.properties

其中,myworkload表示我自己的workload,可以替换成其它已经提供的,比如workloada;db.properties表示连接本地MYSQL数据库的信息。

等待几个小时,完成之后,数据库中会有一千万条数据,使用下面的方式可以导出这些数据到一个csv文件中。

1)先查看路径:show variables like '%secure%';
2)使用上一步所查到的路径:select * from ycsb.usertable into outfile 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/mytablezipfian.csv' FIELDS TERMINATED BY ' '  OPTIONALLY ENCLOSED BY '"'   LINES TERMINATED BY '\r\n';

下图表示的是数据库中部分数据。在测试的过程中,这些数据会自动写入数据库。
在这里插入图片描述

导出成CSV文件之后:
在这里插入图片描述

其它有用的信息:
https://github.com/brianfrankcooper/YCSB/blob/master/jdbc/README.md

谢谢

猜你喜欢

转载自blog.csdn.net/liangyihuai/article/details/121929023