本系列其他文章见:《响应式Spring的道法术器》。
前情提要:Spring WebFlux快速上手 | Spring WebFlux性能测试 | Spring WebClient性能测试
1.4.4 同步与异步数据库驱动的性能对比
许多数据库已陆续推出官方的异步驱动,在Spring Data Reactive中,已经集成了Mongo、Casandra、Redis、CouchDB的异步驱动。
在Spring WebFlux中使用 Reactive Mongo的示例见:http://blog.csdn.net/get_set/article/details/79480233。
这一节我们通过使用YSCB对MongoDB的同步和异步驱动的性能基准测试,来观察异步驱动的优势。
YCSB(Yahoo! Cloud Serving Benchmark)是雅虎开源的一款用于测试各类云服务/NoSQL/键值对存储的性能基准测试工具。YCSB很赞,使用起来很简单,我们就按照wiki介绍来操作即可。
1)准备YCSB
如果使用Windows,请参考这里来预先安装必要的软件和工具。
获取YCSB有两种方式,一种是直接下载压缩包:
curl -O --location https://github.com/brianfrankcooper/YCSB/releases/download/0.12.0/ycsb-0.12.0.tar.gz
tar xfvz ycsb-0.12.0.tar.gz
cd ycsb-0.12.0
另一种是基于源码构建:
git clone git://github.com/brianfrankcooper/YCSB.git
cd YCSB
mvn clean package
此时就可以使用bin/ycsb
命令来进行性能测试了,运行一下:
usage: bin/ycsb command databse [options]
Commands:
load Execute the load phase
run Execute the transaction phase
shell