前幾天把影像紀錄區的 MongoDB 加入 Master/Slave 機制,目前是 Master + 2 x Slaves,但我非常的白痴,以為這樣設定建立好之後就沒事了,也以為網站效能會提升之類的,當我在看系統資源監控的時候發現兩個 Slaves 的使用率好低好低,低到好像沒有在運作一般。
沒錯,在 MongoDB 設定完之後,Python 驅動 MongoDB 的 pymongo 要使用 MasterSlaveConnection 指定誰是 Master、Slaves,這樣才真的可以讓這機制產生效用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymongo import Connection | |
from pymongo.master_slave_connection import MasterSlaveConnection | |
Master = Connection() | |
Slaves = [Connection('127.0.0.1', 27018), Connection('127.0.0.1', 27019)] | |
db = MasterSlaveConnection(Master, Slaves).YOUR_dbs | |
print db.collection_names() |
就這麼簡單設定完成!影像紀錄區有明顯的感覺到資料讀取速度有比較快了!MongoDB 的文件提到如果發生意外,怎樣對調 Master 與 Slave,只是看著看著笑出來了,因為寫的好詳細 XD
至於 MongoDB 另外一個與資料庫分佈有關的 sharding,我想目前應該是實作不到,一方面影像紀錄區的資料量沒這麼多,另一方面是我也沒多的機器來操作,不過我倒是有想到 grs 要不要來建一個各股歷史資料庫,把證交所的資料倒進來,好像也可以齁!
沒有留言:
張貼留言