我正在构建一个应用程序,我的用户可以在其中管理字典。一项功能是上传文件以初始化或更新字典的内容。
我首先关注的结构部分是Dictionary -[:CONTAINS]->Word
. 从一个空数据库(Neo4j 1.9.4,但也尝试过 2.0.0M5)开始,在分布式环境中通过 Spring Data Neo4j 2.3.1 访问(因此使用 SpringRestGraphDatabase,但使用 localhost 进行测试),我正在尝试加载 7k 字在 1 个字典中。但是,在具有核心 i7、8Gb RAM 和 SSD 驱动器(ulimit 提高到 40000)的 linux 上,我无法在不到 8/9 分钟内完成它。
我已经阅读了很多关于使用 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);
}