2020年4月8日 星期三

attribute 的記憶體需求

Vespa 的欄位如果 index-type 被宣告為 attribute 的話,就會直接被放在記憶體上,因此實務上會需要估計到底需要多少記憶體才能撐住所有的資料的問題。

概略的方向是說,primitive type 像是數字(int、long、byte、double)、boolean 等需要的記憶體空間都是固定的,而 string 需要的記憶體空間則跟 string 的平均長度以及有多少個不重複的 string 有關。從這個描述其實可以看出,因為 Vespa 的背後有一定程度是 Java 寫的,所以 string 的這個特性多半是因為 JVM 有 String Pool 的關係吧。

Vespa 文件上其實沒有明確地講到底 primitive type 要吃多少記憶體,不過從提供的 spreadsheet 內容可以推測,primitive type 的記憶體用量應該是直接以 JVM 來計算的:

  • int:4 bytes
  • long:8 bytes
  • double:8 bytes
  • boolean:0.125 bytes(嗯…這不知道是什麼鬼 XD,不過 Java 的 boolean 好像也沒有明確定義 size)

另外當使用了像是 array、map 之類的結構時,會產生額外的記憶體使用:

  • Enum index width:4 bytes
  • Enum value width:4 bytes
  • Multivalue index width:4 bytes
  • Reference count width:4 bytes
  • Weight width:4 bytes

attribute 欄位有設定 fast-search 時,因為會建立 index tree,因此會額外多出被稱為 posting list 的記憶體使用量:

  • Posting entry width (singlevalue):4 bytes
  • Posting entry width (multivalue):8 bytes
  • Posting index width:4 bytes

此外因為每個 document 都會有 document ID,所以建立一個 document 最起碼就有 document ID 的低消:

  • Document id width:4 bytes
參考資料
  1. Attribute Memory Usage

沒有留言: