运行环境:centos 7.5 + cockroachDB 2.0.5
cockroachDB 作为NewSQL的代表,支持传统的OLTP和部分OLAP功能。cockroachDB是基于postgresql协议的,因此使用sysbench进行压力测试。
sysbench支持MySQL和postgresql进行压力测试的工具。
#yum -y install postgresql postgresql-libs
默认安装的pg客户端版本是9.2版本的。
1.准备工作:
搭建好单机的cockroachDB,安装好pg驱动和客户端。
# ./cockroach version
Build Tag: v2.0.5
Build Time: 2018/08/13 17:59:42
Distribution: CCL
Platform: linux amd64 (x86_64-unknown-linux-gnu)
Go Version: go1.10
C Compiler: gcc 6.3.0
Build SHA-1: 3f2f0f5eea9b9d552e471eba8c37504a0595342f
Build Type: release
2.登录创建压力测试专用的用户和数据库:
# psql -h 192.168.0.151 -Uroot -p 26257
psql (10.5, server 9.5.0)
Type "help" for help.
root=> create user backup with password 'backup';
ERROR: cluster in insecure mode; user cannot use password authentication
root=> create user backup ;
CREATE USER 1
root=> grant all on database system to backup;
ERROR: user backup must not have ALL privileges on system object with ID=1
root=> create database sbtest;
CREATE DATABASE
root=> grant all on database sbtest to backup;
创建的数据库为sbtest,用户为backup,对sbtest具有全部的权限。
3.下载和安装sysbench:
# wget http://repo.percona.com/release/7/RPMS/x86_64/sysbench-1.0.15-2.el7.x86_64.rpm
#yum -y install libaio
#yum -y localinstall sysbench-1.0.15-2.el7.x86_64.rpm
4.压力测试初始:
#sysbench /usr/share/sysbench/oltp_read_only.lua --pgsql-host=192.168.0.151 --pgsql-port=26257 --pgsql-db=sbtest --pgsql-user=backup --pgsql-password= --table_size=100 --tables=10 --threads=4 --time=60 --report-interval=10 --db-driver=pgsql prepare
# sysbench /usr/share/sysbench/oltp_read_only.lua --pgsql-host=192.168.0.151 --pgsql-port=26257 --pgsql-db=sbtest --pgsql-user=backup --pgsql-password= --table_size=100 --tables=10 --threads=4 --time=60 --report-interval=10 --db-driver=pgsql run
--下面为初步测试的结果:
sysbench 1.0.15 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 4
Report intermediate results every 10 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
[ 10s ] thds: 4 tps: 48.29 qps: 777.48 (r/w/o: 680.51/0.00/96.97) lat (ms,95%): 137.35 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 4 tps: 48.37 qps: 771.87 (r/w/o: 675.14/0.00/96.73) lat (ms,95%): 147.61 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 4 tps: 44.61 qps: 713.11 (r/w/o: 623.99/0.00/89.13) lat (ms,95%): 176.73 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 4 tps: 46.19 qps: 740.22 (r/w/o: 647.74/0.00/92.48) lat (ms,95%): 150.29 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 4 tps: 37.30 qps: 596.42 (r/w/o: 521.82/0.00/74.60) lat (ms,95%): 204.11 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 4 tps: 33.71 qps: 538.00 (r/w/o: 470.58/0.00/67.43) lat (ms,95%): 272.27 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 36246
write: 0
other: 5178
total: 41424
transactions: 2589 (43.06 per sec.)
queries: 41424 (688.96 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.1226s
total number of events: 2589
Latency (ms):
min: 21.47
avg: 92.81
max: 634.94
95th percentile: 179.94
sum: 240274.41
Threads fairness:
events (avg/stddev): 647.2500/4.26
execution time (avg/stddev): 60.0686/0.01
经过尝试,cockroachdb 还是支持sysbench进行压力测试的。后续可以对cockroachdb的集群进行全面的压力测试。
cockroachDB 官方的压力测试使用的tpcc工具。
参考:
https://www.cockroachlabs.com/docs/stable/performance-benchmarking-with-tpc-c.html