Things to do platform, MongoDB is the first choice

At least the day before yesterday touched a shoe Group has caused the platform to do things, find the MongoDB document database profound understanding is not enough. Today again host the two Linux CentOS install MongoDB database, it verified its advanced features. The following experience.

A, MongoDB no defined initial structure of the conducive things loose management data.

1, we insert two document data, "name", "color", "failure" is not defined in advance metadata

> db.mxCollection.insert({"name":"car1","color":"yello"})

WriteResult({ "nInserted" : 1 })

> db.mxCollection.insert({"name":"car1","failure":"yes"})

WriteResult({ "nInserted" : 1 })

2, the two data query, data not found mysql, irregular column of memory cells; and the default metadata has _id, facilitate retrieval uniqueness

> db.mxCollection.find()

{ "_id" : ObjectId("5cee854cc74bc88162353db6"), "name" : "car1", "color" : "yello" }

{ "_id" : ObjectId("5cee8589f918f3b3837a6c81"), "name" : "car1", "failure" : "yes" }

3, MongoDB architecture directly on the disk, not on HDFS

Standard two thick files for the database file.

[root@ecs-maxing-0001 bin]# cd /data/db

[root@ecs-maxing-0001 db]# ls

journal  local.0  local.ns  maxing.0  maxing.ns  mongod.lock  storage.bson  _tmp

Two, MongoDB native support for separate read and write, and master automatic switchover

1, with the addition of secondary nodes command rs.add primary node when the master node death, automatically connects the standby node.

2, compared to the master-slave synchronization mysql, mysql proxy switch node requires software support, while the native support MongoDB database. Have to say, a rising star of the database really advanced a lot.

Three, MongoDB native support for data slice, auto retractable lateral

Shard node for real data storage node, and then the assignment ConfigServer management data, RouterSDK end mounted App. By communicating with configServer RouterSDK, the automatic selection Shard nodes, to meet the needs of data stored in different servers. Router front-end routing, whereby the client access, and the whole cluster look like a single database front-end applications can transparently use to achieve decentralized.

Meanwhile Shard nodes support automatic elastic expansion, stretching, any increase, decrease does not affect the business of running a server.

MongoDB to the center, support uninterrupted business expansion, certainly more advanced than complex distributed database configuration Mysql simple a lot.

Due to limited space, tomorrow we test the actual effect of fragmentation of databases.

Four, MongoDB can dramatically speed up data retrieval time by indexing

物联网的时代,数据增加非常之快,且数据量非常之在。比如一个物联网的智能穿戴手环,一天可能增加10M的数据量,后期的数据检索时间将非常痛苦。例如,想查询一年内,所有的走路步数,实际已经完成了一次count()计算。如果没有建索引,如果数据量很多,有可能十几分钟都难以得到结果。建索引后效果将提升很多,有利于物联网数据的大数据快速检索。

1、建立索引

> db.mxCollection.createIndex({"name":1})

{

        "createdCollectionAutomatically" : false,

        "numIndexesBefore" : 1,

        "numIndexesAfter" : 2,

        "ok" : 1

}

2、实测在1GB左右的数据量,从优化前的执行15.15S到优化后降至0.013S,性能提升了1000多倍。

> db.mxCollection.find({"name":"hello"}).pretty()

{ "_id" : ObjectId("5cee8b41d0e361b43e717d4d"), "name" : "hello" }

希望以上文章能帮到您。

更多内容实时更新,请访问公众号。    

 

点击这里,获取最高¥1888阿里云产品通用代金券

Guess you like

Origin blog.csdn.net/qq_29718979/article/details/90679239