時(shí)間:2023-10-18 01:30:01 | 來源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-10-18 01:30:01 來源:網(wǎng)站運(yùn)營(yíng)
如何有效地進(jìn)行 MongoDB 的數(shù)據(jù)容量規(guī)劃?:{ "name": "TJ Tang", "company": "TAPDATA", "title": " CTO", "portraits": { "mimetype": "xxx", "data": "xxxx" }}
{ "name": "TJ Tang", "company": "TAPDATA", "title": " CTO", "portraits": { "mimetype": "xxx", "data": "xxxx" }, "addresses": [ { "type": "home", .... }, { "type": "work", .... } ]}
{ "name": "TJ Tang", "company": "TAPDATA", "title": " CTO", "portraits": { "mimetype": "xxx", "data": "xxxx" }, "addresses": [ { "type": "home", .... }, { "type": "work", .... } ], "groups":[ {"name":"FRI"}, {"name":"DF"}, ]}
{ "_id":"10000000022200000222:CA2091", "icao":"CA2091", "ts":ISODate("2022-04-03T20:21:35.000+0000"), "events":{ "tem":35.3, "humidity":50.3, "lon":38.345, "lat":58.987, "open":"0", "b":"b" "p":[123,245], "s":91 }}
我們假設(shè)有10萬個(gè)設(shè)備,每分鐘上報(bào)一條數(shù)據(jù),一年的數(shù)據(jù)量大約52560*100W = 525億數(shù)據(jù),約10TB;每分鐘1條 | ||
---|---|---|
文檔條數(shù) | 52.5B | 10W * 365 * 24 * 60 |
索引大小 | 6364GB | 10W * 365 * 24 * 60 * 130 |
_id index | 1468GB | |
{ts:1,icao:1} | 4895GB | |
文檔平均大小 | 92Bytes | |
數(shù)據(jù)大小 | 4503GB | 10W * 365 * 24 * 60 * 92 |
{ "_id": "10000000022200000222:CA2091", "icao": "CA2091", "ts": ISODate("2022-04-03T20:00:00.000+0000"),//每小時(shí) "events": [//每小時(shí)60條數(shù)據(jù),集合條數(shù)固定 { "tem": 35.3, "humidity": 50.3, "lon": 38.345, "lat": 58.987, "open": "0", "b": "b", "p": [ 123, 245 ], "s": 91, "ts": ISODate("2022-04-03T20:01:00.000+0000")//每分鐘 }, { "tem": 35.3, "humidity": 50.3, "lon": 38.345, "lat": 58.987, "open": "0", "b": "b", "p": [ 123, 245 ], "s": 91, "ts": ISODate("2022-04-03T20:02:00.000+0000") } ]}
這里我們一個(gè)文檔可以存儲(chǔ)一個(gè)小時(shí)的設(shè)備數(shù)據(jù),而events集合中的數(shù)據(jù)條數(shù)是固定的,每小時(shí)60條。指標(biāo) | 每分鐘1條 | 每小時(shí)一個(gè)文檔 |
---|---|---|
文檔條數(shù) | 52.5B | 876 M |
索引大小 | 6364GB | 106 GB |
_id index | 1468GB | 24.5 GB |
{ts:1,icao:1} | 4895GB | 81.6 GB |
文檔平均大小 | 92Bytes | 758 Bytes |
數(shù)據(jù)大小 | 4503GB | 618 GB |
場(chǎng)景 | 痛點(diǎn) | 設(shè)計(jì)模式方案及優(yōu)點(diǎn) |
---|---|---|
時(shí)序數(shù)據(jù) | 數(shù)據(jù)點(diǎn)采集頻繁,數(shù)據(jù)量太多 | 利用文檔內(nèi)嵌數(shù)組,將一個(gè)時(shí)間段的數(shù)據(jù)聚合到一個(gè)文檔里 |
物聯(lián)網(wǎng) | 大量減少文檔數(shù)量 | |
智慧城市 | 大量減少索引占用空間 | |
智慧交通 |
場(chǎng)景 | 痛點(diǎn) | 設(shè)計(jì)模式方案及優(yōu)點(diǎn) |
---|---|---|
產(chǎn)品屬性 ‘color’, ‘size’, ‘dimensions’, …物聯(lián)網(wǎng),多語言(多國家)屬性 | 文檔中有很多類似的字段,會(huì)用于組合查詢搜索,需要建很多索引 | 轉(zhuǎn)化為數(shù)組,一個(gè)索引解決所有查詢問題 |
{ "_id": ObjectId("5de26f197edd62c5d388babb"), "name": "TJ", "company": "Tapdata"}
新增手機(jī)號(hào)后版本:{ "_id": ObjectId("5de26f197edd62c5d388babb"), "name": "TJ", "company": "Tapdata", "phone":"182XXXX8888"}
解決方案:增加一個(gè)版本字段:{ "_id": ObjectId("5de26f197edd62c5d388babb"), "name": "TJ", "company": "Tapdata", "phone":"182XXXX8888", "schema_version": 2.0}
場(chǎng)景 | 痛點(diǎn) | 設(shè)計(jì)模式方案及優(yōu)點(diǎn) |
---|---|---|
任何有版本衍變的數(shù)據(jù)庫 | 文檔模型格式多,無法知道其合理性,升級(jí)時(shí)候需要更新太多文檔 | 增加一個(gè)版本號(hào)字段;快速過濾掉不需要升級(jí)的文檔;升級(jí)時(shí)候?qū)Σ煌姹镜奈臋n做不同的處理 |
場(chǎng)景 | 痛點(diǎn) | 設(shè)計(jì)模式方案及優(yōu)點(diǎn) |
---|---|---|
網(wǎng)頁計(jì)數(shù);各種結(jié)果不需要準(zhǔn)確的排名; | 寫入太頻繁,消耗系統(tǒng)資源 | 間隔寫入,每隔10次或者100次,大量減少寫入需求 |
{ "product": "Bike", "sku": "abc123456", "quantitiy": 20394, "daily_sales": 40, "weekly_sales": 302, "monthly_sales": 1419}db.inventory.update({_id:123},{$inc: { quantity: -1, daily_sales: 1, weekly_sales: 1, monthly_sales: 1, } })
場(chǎng)景 | 痛點(diǎn) | 設(shè)計(jì)模式方案及優(yōu)點(diǎn) |
---|---|---|
準(zhǔn)確排名,排行榜 | 統(tǒng)計(jì)計(jì)算耗時(shí),計(jì)算時(shí)間長(zhǎng) | 模型中直接增加統(tǒng)計(jì)字段;每次更新數(shù)據(jù)時(shí)候同時(shí)更新統(tǒng)計(jì)值 |
關(guān)鍵詞:數(shù)據(jù),容量,規(guī)劃
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。