2

我正在构建一个应用程序,我的用户可以在其中管理字典。一项功能是上传文件以初始化或更新字典的内容。

我首先关注的结构部分是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);
}
4

2 回答 2

1

我通过创建一些 CSV 文件然后从 Neo4j 读取它来解决此类问题。需要进行这样的步骤:

  1. 编写一些获取输入数据的类并基于它创建 CSV 文件(它可以是每个节点类型一个文件,甚至您可以创建将用于建立关系的文件)。

  2. 就我而言,我还创建了允许 Neo4j 通过 HTTP 读取该文件的 servlet。

  3. 创建适当的 Cypher 语句,允许读取和解析该 CSV 文件。我使用了一些示例(如果您使用 Spring Data,还记得标签):

    • 简单的一个:

      load csv with headers from {fileUrl} as line 
         merge (:UserProfile:_UserProfile {email: line.email})
      
    • 更复杂:

      load csv with headers from {fileUrl} as line 
           match (c:Calendar {calendarId: line.calendarId})
           merge (a:Activity:_Activity {eventId: line.eventId})
      on create set  a.eventSummary = line.eventSummary,
           a.eventDescription = line.eventDescription,
           a.eventStartDateTime = toInt(line.eventStartDateTime),
           a.eventEndDateTime = toInt(line.eventEndDateTime),
           a.eventCreated = toInt(line.eventCreated), 
           a.recurringId = line.recurringId
      merge (a)-[r:EXPORTED_FROM]->c
      return count(r)
      
于 2015-07-22T16:28:41.790 回答
0

试试下面

  1. 在执行批处理操作时使用原生 Neo4j API 而不是 spring-data-neo4j。
  2. 分批提交,即可能是每 500 个单词

注意:SDN 添加的某些属性 ( type ) 在使用本机方法时会丢失。

于 2013-10-25T13:25:46.563 回答