使用Neo4jTemplate在Rest配置中保存数据太慢

使用Neo4jTemplate在Rest配置中保存数据太慢,neo4j,graph-databases,spring-data-neo4j,Neo4j,Graph Databases,Spring Data Neo4j,我正在使用Spring和Neo4j数据库进行项目。我将我的Neo4j数据库配置为rest Neo4j。以下是配置: <neo4j:config graphDatabaseService="graphDatabaseService" /> <bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase"> <constructo

我正在使用Spring和Neo4j数据库进行项目。我将我的Neo4j数据库配置为rest Neo4j。以下是配置:

<neo4j:config graphDatabaseService="graphDatabaseService" />
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
    <constructor-arg index="0" value="http://localhost:7474/db/data" />
</bean>
这是一个保存项目及其术语关系的示例。因此,每个术语都是一个连接到项目的节点:

public Node saveItem(Item item) {
    Node node = template.createNode();
    node.setProperty(Item.ID, item.getId());
    node.setProperty(Item.NAME, item.getName());
    node.setProperty(Item.DESCRIPTION, item.getDescription());
    node.setProperty("_type", Item.LABEL);

    template.index(INDEX_ID, node, Item.ID, item.getId());

    for(String termContent : item.getTerms()) {
        Node term = termRepository.getNodeByContent(termContent);
        if(term == null) {
            term = termRepository.saveTerm(new Term(termContent));
        } else {
            termRepository.addCountToTerm(term);
        }

        int frequency = 1;          

        Relationship contains = node.createRelationshipTo(term, RelationshipTypes.CONTAINS);
        contains.setProperty(Term.FREQUENCY, frequency);            
    }
    return node;
}
对象
术语库
(它没有扩展
图形库
)的方法与保存用户的方法类似。获取术语的操作如下所示:

public Node getNodeByContent(String content) {
    if(!template.getGraphDatabaseService().index().existsForNodes(INDEX_ID))
        return null;
    return template.lookup(INDEX_ID, Term.CONTENT, content).to(Node.class).singleOrNull();
}
最后,我的问题是什么。即使现在它仍然很慢,插入用户(仅参数id和名称)和索引需要3秒,插入连接到术语的项目需要30秒(对于4个术语-根据实际情况中60-70的数量,这是非常小的数量)

拜托,你能给我一些提示或者其他任何能帮助我解决这类问题的东西吗?
提前谢谢。

这真是一个难题,您的服务器运行在哪里?似乎与网络设置有关

我的意思是SDN超过REST并不快,但也没有那么慢

你也能分享你的课程吗

不应通过导线执行单个特性更新。使用cypher语句一次性创建所有属性


还有neo4jTemplate.createNode(属性映射),它将其作为一个操作来完成。

这非常奇怪。通过HTTP端点的实际流量有多大?是的,非常奇怪。我的服务器在本地主机上运行,所以应用程序服务器和neo4j服务器之间的延迟很小,但我会通过Wireshark跟踪我的网络通信。谢谢你关于个人财产的说明。改变它,现在速度会快一点我在这里还读到:核心API比Cypher快,所以我也选择使用核心API,我将图形模式改为嵌入式,现在它真的很快。
public Node getNodeByContent(String content) {
    if(!template.getGraphDatabaseService().index().existsForNodes(INDEX_ID))
        return null;
    return template.lookup(INDEX_ID, Term.CONTENT, content).to(Node.class).singleOrNull();
}