MongoDB查询性能优化验证及验证

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了MongoDB查询性能优化验证及验证脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

结论:

1、 200w数据,合理使用索引的情况下,单个stationId下4w数据。mongodb查询和排序的性能理想,无正则时client可以在600ms+完成查询,qps300+。有正则时client可以在1300ms+完成查询,qps140+。

2、 Mongodb的count性能比较差,非并发情况下client可以在330ms完成查询,在并发情况下则需要1-3s。可以考虑估算总数的方法,http://blog.sina.COM.cn/s/bLOG_56545fd30101442b.htML

测试环境:mongodb使用 replica set,1主2从,96G内存,版本2.6.5

Mem消耗(4个200w数据的collection):


空间消耗(测试数据最终选定的collection):


Jvm: -XMs2G -Xmx2G

Ping延迟33ms

查询都使用ReadPReference.secondaryPreferred()

无正则

1、 创建stationId,firmId复合引查询场景(200w集合,12个字段)

查询次数:20000

查询条件:多条件查询10条记录,并逐条获取记录

String key = "清泉" + r.nextInt(1000);
Pattern pattern = Pattern.compile(key);
BasicDBObject queryObject = new BasicDBObject("stationId",new BasicDBObject("$in",new Integer[]{20}))
.apPEnd("firmId",new BasicDBObject("$gt",5000))
.append("dealCount",r.nextInt(1000000))); DBCursor cursor = collection.find(queryObject).limIT(10).skip(2);

并发:200

耗时:61566

单次耗时(server):124ms

Qps:324.85

2、 创建stationId,firmId复合引查询场景(200w集合,12个字段)

查询次数:20000

查询条件:多条件查询10条记录排序,并逐条获取记录

String key = "清泉" + r.nextInt(100);
Pattern pattern = Pattern.compile(key);
BasicDBObject queryObject = new BasicDBObject("stationId",new Integer[]{4,20}))
.append("firmId",r.nextInt(1000000))); DBCursor cursor = collection.find(queryObject)
.sort(new BasicDBObject("firmId",1)).limit(10).skip(2);

并发:200

耗时:63187

单次耗时(server):119ms

Qps:316.52

3、 创建stationId,firmId复合引查询场景(200w集合,12个字段)

查询次数:2000

查询条件:多条件查询记录数

String key = "清泉" + r.nextInt(100);
Pattern pattern = Pattern.compile(key);
BasicDBObject queryObject = new BasicDBObject("stationId",r.nextInt(1000000))); 
long count = collection.count(queryObject);

并发:200

耗时:21887

单次耗时(client):280ms

Qps:91.38

有正则

4、 创建stationId,5000)) .append ("dealCount",r.nextInt(1000000))) .append("firmName",pattern); DBCursor cursor = collection.find(queryObject).limit(10).skip(2);

脚本宝典总结

以上是脚本宝典为你收集整理的MongoDB查询性能优化验证及验证全部内容,希望文章能够帮你解决MongoDB查询性能优化验证及验证所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。