MongoDB单机与集群性能测试对比
一、测试环境:
数据库名称:test
表名称:user
数据结构:{ "_id" : ObjectId("5da041aa097f398cc2ab295f"), "username" : "zhou92001", "password" : "abcd" }
数据总数:800000
客户端并发数:64(多次测试改变此条件)
客户端Mongo 参数 connectionsPerHost:64(多次测试改变此条件)
客户端测试API: 每次操作包含2次查找(根据_id), 1次更新(根据_id,修改password)(多次测试改变此条件)
MongoDB内存限制:1G
客户端参数配置:
MongoClient client = new MongoClient(addresses, MongoClientOptions.builder()
.connectionsPerHost(64)
.threadsAllowedToBlockForConnectionMultiplier(1)
.connectTimeout(5000)
.maxWaitTime(120000)
.socketKeepAlive(true)
.socketTimeout(0)
.build());
服务器配置:CPU型号:Intel(R) Xeon(R) CPU E3-1230 v5 @ 3.40GHz
内存:32G
硬盘:1T
二、单机测试
- 单机测试一:
客户端并发数:64
客户端Mongo 参数 connectionsPerHost:64
客户端测试API: 每次操作包含2次查找(根据_id), 1次更新(根据_id,修改password)
测试结果:
mongostat:
- 单机测试二:
客户端并发数:500
客户端Mongo 参数 connectionsPerHost:500
客户端测试API: 每次操作包含2次查找(根据_id), 1次更新(根据_id,修改password)
mongostat:
- 单机测试三:
客户端并发数:1000
客户端Mongo 参数 connectionsPerHost:1000
客户端测试API: 每次操作包含2次查找(根据_id), 1次更新(根据_id,修改password)
mongostat:
- 单机测试四:
客户端并发数:64
客户端Mongo 参数 connectionsPerHost:64
客户端测试API: 每次操作包含1次查找(根据_id)
mongostat:
- 单机测试五:
客户端并发数:500
客户端Mongo 参数 connectionsPerHost:500
客户端测试API: 每次操作包含1次查找(根据_id)
mongostat:
三、集群测试
本次集群MongoDB是3台组成集群,每台服务器性能和单机的一样。测试用的客户端启动3个进程同时发送请求。
- 集群测试一:
客户端并发数:每个客户端32
客户端Mongo 参数 connectionsPerHost:64
客户端测试API: 每次操作包含2次查找(根据_id,_id是片键), 1次更新(根据_id,修改password)
mongostat -h localhost:9399 --discover :
- 集群测试二:
客户端并发数:每个客户端64
客户端Mongo 参数 connectionsPerHost:64
客户端测试API: 每次操作包含2次查找(根据_id,_id是片键), 1次更新(根据_id,修改password)
mongostat -h localhost:9399 --discover :
- 集群测试三:
客户端并发数:每个客户端128
客户端Mongo 参数 connectionsPerHost:128
客户端测试API: 每次操作包含2次查找(根据_id,_id是片键), 1次更新(根据_id,修改password)
mongostat -h localhost:9399 --discover :
- 集群测试四:
客户端并发数:每个客户端300
客户端Mongo 参数 connectionsPerHost:500
客户端测试API: 每次操作包含2次查找(根据_id,_id是片键), 1次更新(根据_id,修改password)
mongostat -h localhost:9399 --discover :
- 集群测试五:
客户端并发数:每个客户端64
客户端Mongo 参数 connectionsPerHost:64
客户端测试API: 每次操作包含1次查找(根据_id,_id是片键)
mongostat -h localhost:9399 --discover :
- 集群测试六:
客户端并发数:每个客户端128
客户端Mongo 参数 connectionsPerHost:128
客户端测试API: 每次操作包含1次查找(根据_id,_id是片键)
mongostat -h localhost:9399 --discover :
四、测试结果对比
客户端测试API: 每次操作包含1次查找(根据_id,集群中_id是片键)
数据库连接数 |
单机(QPS) |
集群(QPS) |
64(x3) |
13.5 w |
4.2 x 3 = 12.6 w |
128(x3) |
|
4.2 x 3 = 12.6 w |
300(x3) |
|
|
500(x3) |
17.5 w |
|
1000(x3) |
|
|
客户端测试API: 每次操作包含2次查找(根据_id,集群中_id是片键), 1次更新(根据_id,修改password)
数据库连接数 |
单机(QPS,API的QPS) |
集群(QPS) |
32(x3) |
|
1.0 x 3 = 3.0 w |
64(x3) |
4.5 w |
1.4 x 3 = 4.2 w |
128(x3) |
|
1.43 x 3 = 4.29 w |
300(x3) |
|
1.28 x 3 = 3.84 w |
500(x3) |
5.6 w |
|
1000(x3) |
5.0 w |
|
五:总结
- 总结: 单机的时候,连接数在500左右,QPS达到最大。
- 集群的时候,单个客户端连接数在64左右,QPS达到最大。
- 3台集群最大的QPS,还是比单机的最大QPS要小。
- 连接数太大,性能不但不增加,返回会降低。