[英]Neo4J Very Large Admin Import with limited RAM
我正在為我一直從事的項目將幾 TB 的 CSV 數據導入 Neo4J。 我有足夠的快速存儲估計 6.6TiB,但是機器只有 memory 的 32GB,導入工具建議 203GB 來完成導入。
當我運行導入時,我看到以下內容(我假設它因為內存不足而退出)。 有什么辦法可以用我擁有的有限數量的 memory 導入這個大型數據集嗎? 或者,如果不是我擁有的數量有限的 memory,那么這台機器的主板可以支持的最大 ~128GB。
Available resources:
Total machine memory: 30.73GiB
Free machine memory: 14.92GiB
Max heap memory : 6.828GiB
Processors: 16
Configured max memory: 21.51GiB
High-IO: true
WARNING: estimated number of nodes 37583174424 may exceed capacity 34359738367 of selected record format
WARNING: 14.62GiB memory may not be sufficient to complete this import. Suggested memory distribution is:
heap size: 5.026GiB
minimum free and available memory excluding heap size: 202.6GiB
Import starting 2022-10-08 19:01:43.942+0000
Estimated number of nodes: 15.14 G
Estimated number of node properties: 97.72 G
Estimated number of relationships: 37.58 G
Estimated number of relationship properties: 0.00
Estimated disk space usage: 6.598TiB
Estimated required memory usage: 202.6GiB
(1/4) Node import 2022-10-08 19:01:43.953+0000
Estimated number of nodes: 15.14 G
Estimated disk space usage: 5.436TiB
Estimated required memory usage: 202.6GiB
.......... .......... .......... .......... .......... 5% ∆1h 38m 2s 867ms
neo4j@79d2b0538617:~/import$
長話短說:博士; 使用 Periodic Commit或Transaction Batching
如果您嘗試按照操作手冊:Neo4j Admin Import進行操作,並且您的movies.csv
與該示例中的 movies.csv 相匹配,我建議您USING PERIODIC COMMIT LOAD CSV...
進行更多操作:
neo4j/import/myfile.csv
。
接下來,打開一個瀏覽器實例,運行以下命令(根據您的數據進行調整),並留到明天再執行:
USING PERIODIC COMMIT LOAD CSV FROM 'file:///myfile.csv' AS line
WITH line[3] AS nodeLabels, {
id: line[0],
title: line[1],
year: toInteger(line[2])
} AS nodeProps
apoc.create.node(SPLIT(line[3],';',
注意:有很多方法可以解決此問題,具體取決於您的源數據和您希望創建的 model。 此解決方案僅旨在為您提供一些工具來幫助您繞過 memory 限制。 如果它是一個簡單的 CSV,並且您不關心節點最初獲得的標簽是什么,並且您有標頭,則可以跳過復雜的APOC
,並且可能只執行類似以下的操作:
USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM 'file:///myfile.csv' AS line
CREATE (a :ImportedNode)
SET a = line
原始 Asker 提到每個 label 都有一個單獨的 csv。在這種情況下,擁有一個可以處理所有這些的單一命令可能會有所幫助,而不是需要手動逐步完成操作的每個步驟。
假設有兩種標簽類型,每種都有一個獨特的“id”屬性,一種帶有引用另一個 label 的“parent_id”...
UNWIND [
{ file: 'country.csv', label: 'Country'},
{ file: 'city.csv', label: 'City'}
] AS importFile
USING PERIODIC COMMIT LOAD CSV FROM 'file:///' + importFile.file AS line
CALL apoc.merge.node([importFile.label], {id: line.id}) YIELD node
SET node = line
;
// then build the relationships
MATCH (city :City)
WHERE city.parent_id
MATCH (country :Country {id: city.parent_id)
MERGE (city)-[:IN]->(country)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.