bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

理解MongoDB默認(rèn)的ObjectID-創(chuàng)新互聯(lián)

BSON ObjectID Specification

A BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields must be stored big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure a mostly increasing order. The format:

成都創(chuàng)新互聯(lián)從2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目做網(wǎng)站、成都做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元洛隆做網(wǎng)站,已為上家服務(wù),為洛隆各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575

0 1 2 3 4 5 6 7 8 9 10 11
time machine pid inc

  • TimeStamp. This is a unix style timestamp. It is a signed int representing the number of seconds before or after January 1st 1970 (UTC).
  • Machine. This is the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the virtual machine id.
  • Pid. This is 2 bytes of the process id (or thread id) of the process generating the object id.
  • Increment. This is an ever incrementing value, or a random number if a counter can't be used in the language/runtime.

BSON ObjectIds can be any 12 byte binary string that is unique; however, the server itself and almost all drivers use the format above.

分段查看ObjectId的指令及結(jié)果如下:

  1. > db.test.findOne()._id.toString()  
  2. "50c6b336ba95d7738d1042e3"

ObjectId占用12字節(jié)的存儲(chǔ)空間,由“時(shí)間戳” 、“機(jī)器名”、“PID號(hào)”和“計(jì)數(shù)器”組成。使用機(jī)器名的好處是在分布式環(huán)境中能夠避免單點(diǎn)計(jì)數(shù)的性能瓶頸。使用PID號(hào)的好處是支持同一機(jī)器內(nèi)運(yùn)行多個(gè)mongod實(shí)例。最終采用時(shí)間戳和計(jì)數(shù)器的組合來(lái)保證唯一性。

時(shí)間戳

確保ObjectId唯一性依賴的是時(shí)間的順序,不依賴時(shí)間的取值,因此集群節(jié)點(diǎn)的時(shí)間不必完全同步。既然ObjectId已經(jīng)有了時(shí)間戳,那么在文檔中就可以省掉一個(gè)時(shí)間戳了。在使用ObjectID提取時(shí)間時(shí),應(yīng)注意到MongoDB允許各節(jié)點(diǎn)時(shí)間不一致這一細(xì)節(jié)。

下面是查看時(shí)間戳的兩種寫法:

  1. > db.test1.findOne()._id.getTimestamp()
  2. "2012-12-12T03:52:45Z"

機(jī)器名

機(jī)器名通過(guò)Md5加密后取前三個(gè)字節(jié),應(yīng)該還是有重復(fù)概率的,配置生產(chǎn)集群時(shí)檢查一下總不會(huì)錯(cuò)。另外,我也注意到重啟MongoDB后MD5加密結(jié)果會(huì)發(fā)生變化,在利用ObjectID提取機(jī)器名信息時(shí)需格外注意。

PID號(hào)

注意到每次重啟mongod進(jìn)程后PID號(hào)通常會(huì)發(fā)生變化就可以了。

計(jì)數(shù)器

計(jì)數(shù)器占3個(gè)字節(jié),表示的取值范圍就是256*256*256-1=16777215。不妨認(rèn)為MongDB性能的極限是單臺(tái)設(shè)備一秒鐘插入一千萬(wàn)條記錄。以目前的水平看,單臺(tái)設(shè)備一秒鐘插入一萬(wàn)條就很不錯(cuò)了,因此ObjectID計(jì)數(shù)器的設(shè)計(jì)是夠用的。

循環(huán)插入了一些記錄,下面的查詢中b是循環(huán)計(jì)數(shù)器,可以看出我機(jī)器上的ObjectId計(jì)數(shù)器是按順序增加的:

  1. > parseInt(db.test.findOne({b:1000})._id.toString().substring(28,34),16)  

以下代碼源自:http://www.cnblogs.com/xjk15082/archive/2011/09/18/2180792.html

  1. 構(gòu)建objectId  
  2. publicclass
  3. int
  4. int
  5. int
  6. public
  7. int
  8. true
  1. 機(jī)器碼和進(jìn)程碼的生成  
  2. privatestaticint
  3. static
  4. try
  5. int
  6. new
  7. while
  8. "machine piece post: "
  9. int
  10. intnew
  11. try
  12. catch
  13. class
  14. int
  15. new
  16. "process piece: "
  17. "machine : "
  18. catch
  19. thrownew

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)站名稱:理解MongoDB默認(rèn)的ObjectID-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://vcdvsql.cn/article10/hdjgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄全網(wǎng)營(yíng)銷推廣品牌網(wǎng)站建設(shè)做網(wǎng)站軟件開發(fā)微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)