oltpbenchmark

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索

oltpbenchmark是一套Java写的数据库效能测试程式。

环境

这篇所提到的设定主要是在Ubuntu 18.04下的KubernetesDocker)内的情境。

安装

先安装并且设定需要的软件:

sudo apt install -y ant default-jdk openjdk-8-jdk git locales tzdata
update-alternatives --config java
# Use Java 8

取得并且编译:

cd ~
git clone https://github.com/oltpbenchmark/oltpbench.git
cd ~/oltpbench
ant clean
ant

设定

cd ~/oltpbench
cp config/tpcc_config_postgres.xml config/tpcc.xml
vim config/tpcc.xml
# Change "DBUrl", "username", and "password".

测试

先建立表格并且产生测试资料:

cd ~/oltpbench
./oltpbenchmark -b tpcc -c config/tpcc.xml --create=true
./oltpbenchmark -b tpcc -c config/tpcc.xml --load=true

实际测试:

# Test it:
cd ~/oltpbench
./oltpbenchmark -b tpcc -c config/tpcc.xml --execute=true

# Filter rate data only:
cd ~/oltpbench
./oltpbenchmark -b tpcc -c config/tpcc.xml --execute=true | grep --line-buffered 'Rate limited'

# Do benchmark 100 times:
cd ~/oltpbench
for i in {1..100}; do
  ./oltpbenchmark -b tpcc -c config/tpcc.xml --execute=true 2>&1 | grep --line-buffered 'Rate limited'
done

# Get average result:
cd ~/oltpbench
(for i in {1..100}; do
  ./oltpbenchmark -b tpcc -c config/tpcc.xml --execute=true 2>&1 | grep --line-buffered 'Rate limited'
done) | awk '{sum += $(NF - 1); print $(NF - 1)} END {print sum / NR}'

# Brute-force to run all cases:
echo 2 4 8 16 32 64 128 256 512 768 | xargs -n1 | xargs -n1 -I% bash -c "sed -i -e 's/<terminals>[0-9]*/<terminals>%/' config/tpcc.xml; echo %; (for i in {1..100}; do ./oltpbenchmark -b tpcc -c config/tpcc.xml --execute=true 2>&1 | grep 'Rate limited'; done) | awk '{sum += \$(NF - 1)} END {print sum / NR}'"

调整

tpcc.xml内的terminals参数可以调整,以产生足够多的client模拟测试。

其他

CockroachDB

如果以PostgreSQL的界面测试CockroachDB时,会因为CockroachDB不支援CONSTRAINT指到没有index的字段,会需要修改PostgreSQL产生表格时的设定,并且重新编译:

cd ~/oltpbench
sed -i -e 's/^ALTER TABLE /-- ALTER TABLE/' src/com/oltpbenchmark/benchmarks/tpcc/ddls/tpcc-postgres-ddl.sql

# Then rebuild oltpbenchmark:
cd ~/oltpbench
ant clean
ant

另外CockroachDB只支援SERIALIZE模式,所以tpcc.xml内也修改成TRANSACTION_SERIALIZABLE

cd ~/oltpbench
sed -i -e 's/TRANSACTION_READ_COMMITTED/TRANSACTION_SERIALIZABLE/' config/tpcc.xml

外部链接