search

Home  >  Q&A  >  body text

nosql - mongo为什么比mysql快

求高手简单明了的回答一下,越通俗越好。

PHP中文网PHP中文网2781 days ago638

reply all(6)I'll reply

  • 迷茫

    迷茫2017-04-17 11:34:43

    The fundamental reason why writing operations in MongoDB is faster than traditional databases is the memory mapping technology used by Mongo - when writing data, it can be returned to the application as long as it is completed in the memory, so the amount of concurrency is naturally high. The operation of saving to hardware is completed asynchronously in the background. Note that MongoDB has been written to be secure by default in 2.4 (the specific implementation is in the driver), so some students above answered that "unsafe by default" should be based on 2.2 or previous versions.

    The reasons why MongoDB is fast in reading operations are: 1) The design of MongoDB requires that your commonly used data (working set) can be loaded in memory. In this way, most operations only require reading memory, which is naturally very fast. 2) Document pattern design generally means that the data you need are relatively concentrated together (memory or hard disk). As we all know, the most time-consuming hard disk reading and writing is the head positioning time generated by random reading and writing. If the data is concentrated together, Reduces the random reading time required for relational databases to find data from various places (and then join)

    The other one is that as @王子婷 mentioned, Mongo is a distributed cluster so it can be expanded in parallel. At present, the general concurrency of millions of times is achieved simultaneously through clusters of dozens or hundreds of nodes. This is basically impossible for MySQL to do (or it will cost a lot of customization)

    reply
    0
  • 迷茫

    迷茫2017-04-17 11:34:43

    I can’t say so absolutely. In many cases, mongo is not necessarily faster than MySQL

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 11:34:43

    Don’t talk about the scenario, business, or background, just talk about why mongo is faster than mysql? Have you used both? You are here to hack mysql. Go learn how to ask questions!

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 11:34:43

    MySQL is a relational database, which stores tables one by one. Distributed storage requires the tables to be split and stored in different disks

    Do you take it apart vertically or horizontally? If you split a normal query vertically, you need to join

    Horizontal splitting is not that troublesome, but if your statement has a join, no matter which disk the record you are looking for is in, it will traverse all disks to generate the join result

    Can it be slow?

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 11:34:43

    Simple and clear:

    • MongoDB’s default writes are all unsafe writes, that is, the data will be temporarily stored in the memory and a "successful" result will be returned before the writing is completed
    • MongoDB is a non-relational database and supports relatively few query operations
    • MongoDB is designed for distributed clusters (for example, using ObjectID instead of sequential ID), and is easy to expand

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 11:34:43

    If the amount of data is large, it is recommended not to use mongo

    reply
    0
  • Cancelreply