一、前言
OLTPbenchmark是一个多线程负载生成器。该框架被设计成能够针对任何启用JDBC的关系数据库产生可变速率、可变混合负载。该框架还提供数据收集功能,例如,每事务类型的延迟和吞吐量日志。OLTP-Benchmark是一种模块化、可扩展和可配置的OLTP基准测试工具。
二、安装
1、前期准备:
1)安装好java(v1.7 or newer);
2)安装好ant;
2、从github上下载oltp-benchmark的源代码
git clone https://github.com/oltpbenchmark/oltpbench.git
3、进入到oltpbench中用ant进行编译 (注:主要起作用的是里边的build.xml文件)
第一步:进入 oltpbench 目录
$cd oltpbench
第二步:You then need to install Apache Ivy. We use Ivy to download all of the dependencies for the project. OLTP-Bench includes a helper command to install this in your home directory (in $HOME/.ant/lib):
oltpbench $ ant bootstrap
Buildfile: /Users/jiaoxiaoliu/oltpbench/build.xml
bootstrap:
[mkdir] Created dir: /Users/jiaoxiaoliu/.ant/lib
[get] Getting: http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar
[get] To: /Users/jiaoxiaoliu/.ant/lib/ivy.jar
[get] http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar permanently moved to https://repo1.maven.org:443/fromsearch?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar
[get] https://repo1.maven.org:443/fromsearch?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar permanently moved to https://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar
BUILD SUCCESSFUL
Total time: 9 seconds
第三步 You can the download all of the dependencies with this command:
oltpbench$ ant resolve
Buildfile: /Users/jiaoxiaoliu/oltpbench/build.xml
resolve:
[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
[ivy:retrieve] :: loading settings :: file = /Users/jiaoxiaoliu/oltpbench/ivysettings.xml
[ivy:retrieve] :: resolving dependencies :: com.oltpbenchmark#oltpbench;1.0
[ivy:retrieve] confs: [default, master, compile, provided, runtime, test, system]
。。。。。。
[ivy:retrieve] org.slf4j#slf4j-api;1.5.8 by [org.slf4j#slf4j-api;1.6.1] in [default, compile, runtime]
---------------------------------------------------------------------
| | modules || artifacts |
| conf | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
| default | 77 | 66 | 66 | 14 || 65 | 65 |
| master | 2 | 2 | 2 | 0 || 4 | 4 |
| compile | 77 | 66 | 66 | 14 || 65 | 65 |
| provided | 2 | 2 | 2 | 0 || 4 | 4 |
| runtime | 77 | 66 | 66 | 14 || 65 | 65 |
| test | 5 | 5 | 5 | 0 || 7 | 7 |
| system | 2 | 2 | 2 | 0 || 4 | 4 |
---------------------------------------------------------------------
[ivy:retrieve] :: retrieving :: com.oltpbenchmark#oltpbench
[ivy:retrieve] confs: [default, master, compile, provided, runtime, test, system]
[ivy:retrieve] 68 artifacts copied, 0 already retrieved (33035kB/5051ms)
BUILD SUCCESSFUL
Total time: 7 minutes 9 seconds
第四步 You are now ready to compile the project:
ant build
注 (按照其他博客中的方式)下载源码后,直接进入到oltpbench中用ant进行编译会报错,使用以上安装方式可以解决,参考官方
[javac] private static final Logger LOG = Logger.getLogger(DistributionStatistics.class);
[javac] ^
[javac] 符号: 类 Logger
[javac] 位置: 类 DistributionStatistics
[javac] /Users/jiaoxiaoliu/go/src/gitlab.bj.sensetime.com/diamond/service-providers/oltpbench/src/com/oltpbenchmark/util/Histogram.java:35: 错误: 找不到符号
[javac] private static final Logger LOG = Logger.getLogger(Histogram.class);
[javac] ^
[javac] 符号: 类 Logger
[javac] 位置: 类 Histogram<X>
[javac] 其中, X是类型变量:
4. 准备测试数据库(以mysql为例)
第一步 创建名为tpcc的数据库
mysql> create database tpcc;
Query OK, 1 row affected (0.05 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| tpcc |
+--------------------+
5 rows in set (0.03 sec)
第二步 修改配置文件sample_tpcc_config.xml
oltpbench$vim config/tpcc_config_mysql.xml
<!-- config/sample_tpcc_config.xml -->
<!-- Connection details -->
<dbtype>mysql</dbtype>
<driver>com.mysql.jdbc.Driver</driver>
<DBUrl>jdbc:mysql://localhost:3306/tpcc</DBUrl>
<username>root</username>
<password>mysecretpassword</password>
<isolation>TRANSACTION_SERIALIZABLE</isolation>
第三步 启动一个tpcc数据库(–create=true–load=true),然后运行一个工作负载config/tpcc_config_mysql.xml文件。每5秒汇总结果(-s 5)(延迟、吞吐量),并输出到 outputfile 文件
./oltpbenchmark -b tpcc -c config/tpcc_config_mysql.xml --create=true --load=true --execute=true -s 5 -o outputfile