2014-10-13 37 views
0

我已經開始記錄來自我的網絡的所有DNS查詢,並且想知道哪個是最好的存儲機制。nexted數組的MongoDB文檔與字典

目前我使用的MySQL,但查詢它是有點麻煩(有點由於爲連接慢)和存儲是相當臃腫,所以我從

2014-10-13T08:28:35.570+0200 | 192.168.5.5 | A | 72.21.210.52 | device-metrics-us.amazon.com 

2014-10-13T08:28:44.522+0200 | 192.168.5.9 | CNAME | googleapis.l.google.com | www.googleapis.com 
2014-10-13T08:28:44.522+0200 | 192.168.5.9 | A | 74.125.29.95 | googleapis.l.google.com 

2014-10-13T08:28:45.618+0200 | 192.168.5.5 | CNAME | android.l.google.com | android.clients.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.160 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.165 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.166 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.168 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.162 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.169 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.163 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.164 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.174 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.161 | android.l.google.com 
2014-10-13T08:28:45.618+0200 | 192.168.5.5 | A | 74.125.226.167 | android.l.google.com 

改變了表格數據佈局到NOSQL友好的格式

["2014-10-13T08:28:35.570+0200", "Mon 08:28", "192.168.5.5", ["device-metrics-us.amazon.com"], ["72.21.210.52"]], 
["2014-10-13T08:28:44.522+0200", "Mon 08:28", "192.168.5.9", ["www.googleapis.com", "googleapis.l.google.com"], ["74.125.29.95"]], 
["2014-10-13T08:28:45.618+0200", "Mon 08:28", "192.168.5.5", ["android.clients.google.com", "android.l.google.com"], ["74.125.226.160", "74.125.226.165", "74.125.226.166", "74.125.226.168", "74.125.226.162", "74.125.226.169", "74.125.226.163", "74.125.226.164", "74.125.226.174", "74.125.226.161", "74.125.226.167"]], 

我有這些固定的指標:

0:時間戳,

1:更可讀的時間戳

2:查詢

3的源:陣列,其中所述第一元件是所請求的DNS名,和隨後的元件的CNAME

4:的數組由於所有這些東西也將被保存在內存中,並且結構不會改變,所以爲了節省RAM(存儲服務器已經超出RAM使用量),我認爲我跳過了這些密鑰。

可以嗎?還是我加密鑰的真正的好處,像這樣(甚至是一個單個字符的鍵):

{"timestamp": "2014-10-13T08:28:35.570+0200", "nice": "Mon 08:28", "ip": "192.168.5.5", "query":["device-metrics-us.amazon.com"], "result":["72.21.210.52"]}, 

我真的希望有原始陣列。

我會經常查詢的結果列表中的IP地址,並期望得到初始查詢結果,按時間和設備(零和第2場)

截至目前限制,我計劃使用MongoDB。

對數據格式的任何建議以最大化效率(RAM和速度)和可查詢性?

回答

1

我在這裏寫一些評論僅供參考:

  • BSON的數組實際上是一個文檔結構(當然,不同的數據類型)。例如,[1,2,3] == {"0":1, "1":1, "2":3}BSON spec;
  • 索引是在關鍵字上創建的,使用某個鍵來縮小數據範圍有助於提高查詢性能。所以關鍵是你的結構所必需的。
  • 正如你想要非常節省內存,創建每個字符爲一個字符。

所以,結構你提供

{"timestamp": "2014-10-13T08:28:35.570+0200", "nice": "Mon 08:28", "ip": "192.168.5.5", "query":["device-metrics-us.amazon.com"], "result":["72.21.210.52"]} 

是最好不過了。

+0

好的,謝謝,我也注意到我無法插入普通數組。 –

+0

哦,對於SQL來說,查詢這些數據是一個夢想。 –

+0

@DanielF,你怎麼了? – Wizard