ITeye博客

mongoDB vs mysql 性能对比测试

pingfeng · 2011-04-07 14:44 · 编程语言 · Markdown

测试环境:

  型号名称:    iMac
  处理器名称:    Intel Core 2 Duo
  处理器速度:    3.06 GHz
  处理器数量:    1
  总核心数:    2
  L2 高速缓存:    3 MB
  内存:    4 GB
  总线速度:    1.07 GHz

测试方案:

js脚本向mongo向一个collection里插入一百万个文档

用mongo的ruby driver做CRDU操作

ruby脚本向mysql的表插入100万条记录

用AR做CRDU操作

 

测试AR的CRDU与mongo ruby driver的CRDU性能

 

测试结果:

 

mysql vs mongo

                                                      |      AR |   MONGO
---------------------------------------------------------------------------
Model.create                                     x1000 |   1.235 |  0.337
Resource#update                                  x1000 |   0.765 |  0.079
Resource#destroy                                   x10 |   0.009 |  0.00074

Model.first                                      x1000 |   0.279 |  0.223

Model.find(id)                                   x1000 |   0.240 |  0.304
Model.find not use index                           x10 |   6.359 |  5.04
Model.find not use index                              x10 |  18.952 |  10.479  ( mysql:big field, mongo:find sub-doc)           

 

结果分析:

 

虽然mysql记录与mongo的文档不是完全一致的,但在同一水平上。

 

1. 基本查找:找first与通过id查找,两者差不多

 

2. 无索引查找:mongo要比mysql快一点 。最后一行数据是指mysql有大字段,而mongo则对子文档字段作查找。

 

3. create, update, destroy, mongo基本要比mysql快一个数量级 。

 

测试脚本见附件

评论(16)

  1. #16 楼 · forchenyun · 2011-04-17 20:38

    百万级别,mysql不是问题,建议你可以看看mongo的亿级别数据量测试: http://blog.nosqlfan.com/html/1388.html 一般来说,IO密集型应用,缓存命中率是性能的唯一评测点

  2. #15 楼 · calvinlyc · 2011-04-14 07:27

    ..........2个完全不同的东西,去比他干什么呢

  3. #14 楼 · pingfeng · 2011-04-13 10:46

    Saito writes:

    [quote=From Mississippi][size=small] The three operations that this chapter focused on (inserts, removes, and updates) seem instantaneous because none of them waits for a database response. They are not asyn- chronous; they can be thought of as “fire-and-forget” functions: the client sends the documents to the server and immediately continues. The client never receives an “OK, got that” or a “not OK, could you send that again?” response.[/size] [size=small] The benefit to this is that the speed at which you can perform these operations is terrific. You are often only limited by the speed at which your client can send them and the speed of your network. This works well most of the time; however, sometimes some- thing goes wrong: a server crashes, a rat chews through a network cable, or a data center is in a flood zone. If the server disappears, the client will happily send some writes to a server that isn’t there, entirely unaware of its absence. For some applications, this is acceptable. Losing a couple of seconds of log messages, user clicks, or analytics in a hardware failure is not the end of the world. For others, this is not the behavior the programmer wants (payment-processing systems spring to mind).[/size] [/quote]

    Mongodb CUD上快是肯定且有代价的. 或许你可以在safe mode上再跟mysql"平等"的测试一下. Mongodb1.8 release的Journaling对引用后段的问题会有所帮助,不过怀疑会降低些许Mongodb的性能.没测试过.

    确实,在产品开发中打开了安全模式。如用mongoid的save也没有发现成功和失败的返回。 有时间再测一下安全模式。

  4. #13 楼 · pingfeng · 2011-04-13 10:44

    rocy writes:

    js 和 ruby 两种语言也不在一个量级上啊.. 都用ruby来做麻烦么?

    是都是用ruby来写,只是100万个文档生成的时候用js做的。

    “js脚本向mongo向一个collection里插入一百万个文档

    用mongo的ruby driver做CRDU操作

    ruby脚本向mysql的表插入100万条记录

    用AR做CRDU操作”

  5. #12 楼 · pingfeng · 2011-04-13 10:32

    yongdi2 writes:

    学习下。lz是华为的吧,看工牌带子

    参加QCon会议的带子,不是华为的带子,呵呵

  6. #11 楼 · skzr.org · 2011-04-12 21:07

    freish writes:

    一个用ruby,一个用js,外部环境都不同,还谈何比较!

    是阿,没有想象中的快

  7. #10 楼 · Saito · 2011-04-12 19:06

    From Mississippi writes:

    [size=small] The three operations that this chapter focused on (inserts, removes, and updates) seem instantaneous because none of them waits for a database response. They are not asyn- chronous; they can be thought of as “fire-and-forget” functions: the client sends the documents to the server and immediately continues. The client never receives an “OK, got that” or a “not OK, could you send that again?” response.[/size] [size=small] The benefit to this is that the speed at which you can perform these operations is terrific. You are often only limited by the speed at which your client can send them and the speed of your network. This works well most of the time; however, sometimes some- thing goes wrong: a server crashes, a rat chews through a network cable, or a data center is in a flood zone. If the server disappears, the client will happily send some writes to a server that isn’t there, entirely unaware of its absence. For some applications, this is acceptable. Losing a couple of seconds of log messages, user clicks, or analytics in a hardware failure is not the end of the world. For others, this is not the behavior the programmer wants (payment-processing systems spring to mind).[/size]

    Mongodb CUD上快是肯定且有代价的. 或许你可以在safe mode上再跟mysql"平等"的测试一下. Mongodb1.8 release的Journaling对引用后段的问题会有所帮助,不过怀疑会降低些许Mongodb的性能.没测试过.

  8. #9 楼 · freish · 2011-04-12 07:57

    一个用ruby,一个用js,外部环境都不同,还谈何比较!

  9. #8 楼 · orcl_zhang · 2011-04-12 00:31

    不能直接拿这两者性能吧,他们的定位都不同。mysql是关系型数据训,而mongodb是基于文档的。

    后者对关系型数据支持不好,而且没有事务机制,而mongo擅长存储日志,系统动态等没有什么关联,且不太重要的信息。

    不知道,有没有用mogodb,和mysql的混合数据库的经验分享下,有的话透露下,我想尝试下。还有mogodb有木有db缓存?或者这方面的插件之类的。

  10. #7 楼 · rocy · 2011-04-11 23:04

    js 和 ruby 两种语言也不在一个量级上啊.. 都用ruby来做麻烦么?

  11. #6 楼 · dxm1986 · 2011-04-11 22:34
  12. #5 楼 · yongdi2 · 2011-04-11 13:31

    学习下。lz是华为的吧,看工牌带子

  13. #4 楼 · tcray · 2011-04-11 13:05

    云中苍月 writes:

    [quote=tcray]nosql快倒是快啊 但是目前阶段还是无法取代关系数据库啊 复杂的查询就是nosql的一个软肋[/quote] 应用场景不同用不同的产品,用了nosql就别考虑复杂查询,单一产品不可能完美。

    同意 看看自己的东西更注重哪个方面吧 没有完美的东西

  14. #3 楼 · 油炸大龙虾 · 2011-04-11 10:37

    个人认为还是比较一下集群以后的效率才有意义。 复杂查询是设计的问题,mongo无视

  15. #2 楼 · 云中苍月 · 2011-04-11 10:26

    tcray writes:

    nosql快倒是快啊 但是目前阶段还是无法取代关系数据库啊 复杂的查询就是nosql的一个软肋

    应用场景不同用不同的产品,用了nosql就别考虑复杂查询,单一产品不可能完美。

  16. #1 楼 · tcray · 2011-04-11 09:40

    nosql快倒是快啊 但是目前阶段还是无法取代关系数据库啊 复杂的查询就是nosql的一个软肋

评论功能维护中,当前仅展示历史评论。