我正在構建一個應用程序,讓我的用戶可以管理字典。一個功能是上傳文件以初始化或更新字典的內容。Neo4j:插入7k節點很慢(Spring Data Neo4j/SpringRestGraphDatabase)
我關注的一部分結構是Dictionary -[:CONTAINS]->Word
。 從一個空數據庫(Neo4j 1.9.4,但也試過2.0.0M5)開始,通過Spring Data Neo4j 2.3.1在分佈式環境中訪問(因此使用SpringRestGraphDatabase,但使用localhost進行測試),我試圖加載7k 1字典中的單詞。然而,我不能在少於8/9分鐘的時間內完成核心i7,8Gb RAM和SSD驅動器(ulimit提高到40000)的Linux。
我讀過很多關於使用REST加載/插入性能的帖子,我嘗試應用我發現的建議,但沒有更好的運氣。由於我的應用程序限制,BatchInserter工具對我來說似乎不是一個好選擇。
我希望能在幾秒鐘內而不是幾分鐘內加載10k個節點嗎?
這裏是我想出了一個代碼,經過我的所有讀數:
Map<String, Object> dicProps = new HashMap<String, Object>();
dicProps.put("locale", locale);
dicProps.put("category", category);
Dictionary dictionary = template.createNodeAs(Dictionary.class, dicProps);
Map<String, Object> wordProps = new HashMap<String, Object>();
Set<Word> words = readFile(filename);
for (Word gw : words) {
wordProps.put("txt", gw.getTxt());
Word w = template.createNodeAs(Word.class, wordProps);
template.createRelationshipBetween(dictionary, w, Contains.class, "CONTAINS", true);
}
如果您創建所有實體分離並將它們全部保存,會發生什麼情況最後呢?在你的字典類中有一個'Set'適當的註釋,用'new'創建字典和單詞,如普通對象,而不是模板,將所有單詞添加到字典集'字典。addWord(word)',只有在最後你用'template.save(dict)'來堅持這一切。有什麼區別? –
jjaderberg