欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MongoDB分片測(cè)試

 更新時(shí)間:2016年03月24日 11:20:17   作者:我思,故我在  
分片是mongoDB擴(kuò)展的一種方式。分片分割一個(gè)collection并將不同的部分存儲(chǔ)在不同的機(jī)器上,本文給大家介紹MongoDB分片測(cè)試,需要的朋友參考下吧

分片是mongoDB擴(kuò)展的一種方式。分片分割一個(gè)collection并將不同的部分存儲(chǔ)在不同的機(jī)器上。當(dāng)一個(gè)數(shù)據(jù)庫的collections相對(duì)于當(dāng)前空間過大時(shí),你需要增加一個(gè)新的機(jī)器。分片會(huì)自動(dòng)的將collection數(shù)據(jù)分發(fā)到新的服務(wù)器上。

1. 連接到mongos可查看系統(tǒng)相關(guān)信息

configsvr> show dbs
configsvr> use config
configsvr> show collections
onfigsvr> db.mongos.find()
{ "_id" :"racdb:28885", "ping" :ISODate("2016-03-21T09:23:05.106Z"), "up" :NumberLong(1436), "waiting" : true, "mongoVersion" :"3.2.3" }
{ "_id" :"host8.localdomain:28885", "ping" :ISODate("2016-03-21T09:23:07.960Z"), "up" :NumberLong(1427), "waiting" : true, "mongoVersion" :"3.2.3" }
{ "_id" :"host9.localdomain:28885", "ping" :ISODate("2016-03-21T09:23:03.521Z"), "up" :NumberLong(1407), "waiting" : true, "mongoVersion" :"3.2.3" }
configsvr> db.shards.find()
{ "_id" : "shard1","host" : "shard1/host8:28017,racdb:28017" }
{ "_id" : "shard2","host" : "shard2/host8:28018,racdb:28018" }
configsvr> db.databases.find()
{ "_id" :"im_offline_msg", "primary" : "shard1","partitioned" : true }
{ "_id" : "testdb","primary" : "shard2", "partitioned" : true }
{ "_id" : "test","primary" : "shard1", "partitioned" : true }
{ "_id" : "blogdb","primary" : "shard2", "partitioned" : false }

2. 對(duì)數(shù)據(jù)庫啟用分片

2.1 當(dāng)前可連接到 mongos 查看數(shù)據(jù)庫或者集合的分片情況(沒有分片):

mongos> db.stats()
mongos> db.tab.stats()

2.2 對(duì)數(shù)據(jù)庫激活分片功能:

# mongo racdb:28885
mongos>sh.enableSharding("test")
#或者
# mongo racdb:28885
mongos> use admin
mongos> db.runCommand( { enableSharding:"blogdb"} )

2.3 此時(shí)查看數(shù)據(jù)庫分區(qū)情況,partitioned變?yōu)?“true”。

configsvr> use config
switched to db config
configsvr> db.databases.find()
{ "_id" :"im_offline_msg", "primary" : "shard1","partitioned" : true }
{ "_id" : "testdb","primary" : "shard2", "partitioned" : true }
{ "_id" : "test","primary" : "shard1", "partitioned" : true }
{ "_id" : "blogdb","primary" : "shard2", "partitioned" : true }

啟用數(shù)據(jù)庫分片并沒有將數(shù)據(jù)進(jìn)行分開,還需要對(duì) collection 進(jìn)行分片。

3. 對(duì)集合啟用分片

啟用前,有幾個(gè)問題需要考慮的:

選擇哪個(gè)鍵列作為shard key 。(更多參考:Considerations for Selecting Shard Keys)

如果集合中已經(jīng)存在數(shù)據(jù),在選定作為shard key 的鍵列必須創(chuàng)建索引;如果集合為空,mongodb 將在激活集合分片(sh.shardCollection)時(shí)創(chuàng)建索引。

集合分片函數(shù)sh.shardCollection ,

sh.shardCollection(".",shard-key-pattern)

mongos>sh.shardCollection("test.tab", { "_id": "hashed"})

測(cè)試插入數(shù)據(jù):

--使用python命令
#創(chuàng)建python文件
$ vi batch_insert.py
#-*- coding: UTF-8 -*-
import pymongo
client = pymongo.MongoClient("racdb", 28885)
db = client.testdb
#查看testdb數(shù)據(jù)庫中集合信息
print (db.collection_names())
#連接到my_collection集合
print (db.my_collection)
#清空my_collection集合文檔信息
db.my_collection.remove()
#顯示my_collection集合中文檔數(shù)目
print (db.my_collection.find().count())
#插入10000條文檔信息
for i in range(10000):
db.my_collection.insert({"id":i,"name":"Licz"})
#顯示my_collection集合中文檔數(shù)目
print ('插入完畢,當(dāng)前文檔數(shù)目:')
print (db.my_collection.find().count())
#執(zhí)行插入
[mongod@racdb ~]$ python2.7.3batch_insert.py
[u'system.indexes', u'table1',u'my_collection']
Collection(Database(MongoClient(host=['racdb:28885'],document_class=dict, tz_aware=False, connect=True), u'testdb'), u'my_collection')
0

插入完畢,當(dāng)前文檔數(shù)目:

10000
#或是用mongo shell插入測(cè)試數(shù)據(jù)
for (var i=1; i<=100000; i++) {
db.cc.insert({"id": i,"myName" : "cc"+i, "myDate" : new Date()});
}

啟用集合分片

mongos> show collections
mongos> db.cc.find()
mongos> db.cc.createIndex({"id": "hashed" })
mongos> db.cc.getIndexes()
mongos>sh.shardCollection("testdb.cc", { "id": "hashed"})
mongos> db.stats()
mongos> db.cc.stats()
--查看sharding 狀態(tài)
mongos> db.printShardingStatus();

以上內(nèi)容是小編給大家介紹的MongoDB分片測(cè)試,希望對(duì)大家有所幫助!

相關(guān)文章

  • mongodb exception: $concat only supports strings, not NumberInt32解決辦法

    mongodb exception: $concat only supports strings, not Number

    這篇文章主要介紹了mongodb exception: $concat only supports strings, not NumberInt32解決辦法,需要的朋友可以參考下
    2014-06-06
  • MongoDB聚合分組取第一條記錄的案例與實(shí)現(xiàn)方法

    MongoDB聚合分組取第一條記錄的案例與實(shí)現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于MongoDB聚合分組取第一條記錄的案例與實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • 詳解MongoDB中用sharding將副本集分配至服務(wù)器集群的方法

    詳解MongoDB中用sharding將副本集分配至服務(wù)器集群的方法

    副本集是MongoDB的主從復(fù)制中的重要功能,經(jīng)常被用來作額外的備份,這里我們就來詳解MongoDB中用sharding將副本集分配至服務(wù)器集群的方法,首先還是來回顧一下MongoDB中副本集的基本知識(shí):
    2016-07-07
  • MongoDB導(dǎo)出查詢結(jié)果到文件例子

    MongoDB導(dǎo)出查詢結(jié)果到文件例子

    這篇文章主要介紹了MongoDB導(dǎo)出查詢結(jié)果到文件例子,本文直接給出示例代碼,簡(jiǎn)潔易懂,需要的朋友可以參考下
    2015-02-02
  • MongoDB教程之索引介紹

    MongoDB教程之索引介紹

    這篇文章主要介紹了MongoDB教程之索引介紹,本文講解了索引基礎(chǔ)、唯一索引、使用explain、索引管理等內(nèi)容,需要的朋友可以參考下
    2015-05-05
  • MongoDB4.2.5安裝方法操作步驟

    MongoDB4.2.5安裝方法操作步驟

    這篇文章主要介紹了MongoDB4.2.5安裝方法操作步驟,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12
  • MongoDB修改、刪除文檔的域?qū)傩詫?shí)例

    MongoDB修改、刪除文檔的域?qū)傩詫?shí)例

    這篇文章主要介紹了MongoDB修改、刪除文檔的域?qū)傩詫?shí)例,本文講解了刪除集合中所有文檔的一個(gè)域、同時(shí)刪除多個(gè)域、同時(shí)刪除和新增域,需要的朋友可以參考下
    2015-02-02
  • MongoDB賬戶密碼設(shè)置的方法詳解

    MongoDB賬戶密碼設(shè)置的方法詳解

    這篇文章主要給大家介紹了關(guān)于MongoDB賬戶密碼設(shè)置的相關(guān)資料,我們知道m(xù)ysql在安裝的時(shí)候需要我們?cè)O(shè)置一個(gè)數(shù)據(jù)庫默認(rèn)的用戶名和密碼,mongodb也不例外,需要的朋友可以參考下
    2023-09-09
  • MongoDB中的MapReduce簡(jiǎn)介

    MongoDB中的MapReduce簡(jiǎn)介

    這篇文章主要介紹了MongoDB中的MapReduce簡(jiǎn)介,MapReduce是一種計(jì)算模型,簡(jiǎn)單的說就是將大批量的工作(數(shù)據(jù))分解(MAP)執(zhí)行,然后再將結(jié)果合并成最終結(jié)果(REDUCE),需要的朋友可以參考下
    2015-05-05
  • MongoDB教程之?dāng)?shù)據(jù)操作實(shí)例

    MongoDB教程之?dāng)?shù)據(jù)操作實(shí)例

    這篇文章主要介紹了MongoDB教程之?dāng)?shù)據(jù)操作實(shí)例,本文講解了批量插入、數(shù)據(jù)庫清除、數(shù)據(jù)更新、修改器、數(shù)組修改器、upsert等內(nèi)容,需要的朋友可以參考下
    2015-05-05

最新評(píng)論