Mongodb VS Mysql 查询性能
<span style="">原文出处:http://blog.chenlb.com/2010/05/mongodb-vs-mysql-query-performance.html环境:同一台机器,装有 mongodb 1.4, mysql;内存 4g;两个数据库都只有 id 的唯一搜索;数据量 120w 左右,5w 个查询。对它们进行 id 或 ids 查询。
mongodbmysqltotal timeavg time/per querytotal timeavg time/per query1 id/per query11954ms, 00:11,9540ms, 00,078613ms, 00:1:18,6131ms, 00,110 id/per query35885ms, 00:35,8850ms, 00,0107274ms, 00:1:47,2742ms, 00,220 id/per query63714ms, 00:1:3,7141ms, 00,1186398ms, 00:3:6,3983ms, 00,35 thread, 20 id/per query-5ms, 00,5-11ms, 00,1110 thread, 20 id/per query-10ms, 00,10-22ms, 00,22
从上表看:
每次查一个 id 的查询,在基本相同条件下 mongodb 速度是 mysql 的 7 倍。
每次查多个 id (10/20)的查询,mongodb 比 mysql 快 2 倍。
多线程下查多个 id,mongodb 比 mysql 快 1 倍。
从上面的测试来看:主要用在 id 查询或 ids 查询的应用中 mongodb 要优越 mysql。
在插入这些数据的时候,mongodb 更加快于 mysql,插入120w 到 mongodb 用 83159ms, ->00:1:23,159 就够了。mysql 有几十分钟。
当我在实际应用中(kw 级数据量),使用 mongodb 速度没有 mysql 好。原因可能有,mysql 的机器好,mongodb 使用不够得当。继续调整和优化程序吧……
附 mongodb 的 in 查询:
<div style="font-size: 12px; background-color: transparent; width: 671px; margin-left: 9px; padding: 1px;" class="dp-highlighter">
[*]BasicDBObject q = new BasicDBObject();
[*]BasicDBObject in = new BasicDBObject();
[*]
[*]void createQ(Integer[] ids) {
[*] q.put("id", in);
[*] in.put("$in", ids);
[*]}
页:
[1]