0

我正在使用neo4j版本1.8.1spring-data-neo4j版本2.2.0. RELEASE

问题在于neo4j的保存速度。我不明白为什么会这样。该节点在 db 中持续存在大约 30 秒。这是我的模型课。

@NodeEntity
public class GraphUser {


    public static final String FACEBOOK_FRIEND = "FACEBOOK_FRIEND";
    public static final String TWITTER_FOLLOW = "TWITTER_FOLLOW";
    public static final String CONTACT = "CONTACT";
    public static final String KNOWS = "KNOWS";
    public static final String BLOCKED = "BLOCKED";
    public static final String FAVORITE = "FAVORITE";

    @GraphId
    private Long id;

    @Indexed(unique = true, indexType = IndexType.FULLTEXT, indexName = "userIdIndex")
    private String userId;

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "facebookIdIndex")
    private String facebookId;

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "twitterIdIndex")
    private String twitterId;

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "emailIndex")
    private String email;

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "phoneNumberIndex")
    private String phoneNumber;

    private String knowsLevel;

    @RelatedTo(type = FACEBOOK_FRIEND, direction = Direction.BOTH)
    @Fetch
    private Set<GraphUser> facebookRelations = new HashSet<GraphUser>();

    @RelatedTo(type = TWITTER_FOLLOW, direction = Direction.OUTGOING)
    @Fetch
    private Set<GraphUser> twitterRelations = new HashSet<GraphUser>();

    @RelatedTo(type = CONTACT, direction = Direction.OUTGOING)
    @Fetch
    private Set<GraphUser> contacts = new HashSet<GraphUser>();


    @RelatedTo(type = KNOWS, direction = Direction.OUTGOING)
    @Fetch
    private Set<GraphUser> knows = new HashSet<GraphUser>();

    @RelatedTo(type = BLOCKED, direction = Direction.OUTGOING)
    @Fetch
    private Set<GraphUser> blocks = new HashSet<GraphUser>();

    @RelatedTo(type = FAVORITE, direction = Direction.OUTGOING)
    @Fetch
    private Set<GraphUser> favorites = new HashSet<GraphUser>();

    @Query(value = "start user=node({self}), user2=node(*), matchedUser=node(*) " +
            "where has(user2.userId) and has(matchedUser.userId) and has(user.knowsLevel) and has(user2.knowsLevel) and has(matchedUser.knowsLevel) " +
            "and " +
            "user.userId<>matchedUser.userId " +
            "and " +
            "(" +
            "(user.knowsLevel='ALL' and (matchedUser.knowsLevel='ALL' or (user)<-[:KNOWS]-(matchedUser) or ((user)<-[:KNOWS]-(user2)<-[:KNOWS]-(matchedUser) and matchedUser.knowsLevel='SECOND'))) " +
            "or " +
            "(user.knowsLevel='SECOND' and ((user)-[:KNOWS]->(matchedUser) or (user)-[:KNOWS]->(user2)-[:KNOWS]->(matchedUser)) and (matchedUser.knowsLevel='ALL' or (user)<-[:KNOWS]-(matchedUser) or ((user)<-[:KNOWS]-(user2)<-[:KNOWS]-(matchedUser) and matchedUser.knowsLevel='SECOND'))) " +
            "or " +
            "(user.knowsLevel='FIRST' and (user)-[:KNOWS]->(matchedUser) and (matchedUser.knowsLevel='ALL' or (user)<-[:KNOWS]-(matchedUser) or ((user)<-[:KNOWS]-(user2)<-[:KNOWS]-(matchedUser) and matchedUser.knowsLevel='SECOND')))" +
            ") " +
            "return matchedUser")
    @Fetch
    private Iterable<GraphUser> matchedUsers;


    public Long getId() {
        return id;
    }


    public void setId(Long id) {
        this.id = id;
    }


    public String getUserId() {
        return userId;
    }


    public void setUserId(String userId) {
        this.userId = userId;
    }


    public String getFacebookId() {
        return facebookId;
    }


    public void setFacebookId(String facebookId) {
        this.facebookId = facebookId;
    }


    public String getTwitterId() {
        return twitterId;
    }


    public void setTwitterId(String twitterId) {
        this.twitterId = twitterId;
    }


    public String getEmail() {
        return email;
    }


    public void setEmail(String email) {
        this.email = email;
    }


    public String getPhoneNumber() {
        return phoneNumber;
    }

    public String getKnowsLevel() {
        return knowsLevel;
    }

    public void setKnowsLevel(String knowsLevel) {
        this.knowsLevel = knowsLevel;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }


    public Set<GraphUser> getFacebookRelations() {
        return facebookRelations;
    }


    public void setFacebookRelations(Set<GraphUser> facebookRelations) {
        this.facebookRelations = facebookRelations;
    }


    public Set<GraphUser> getTwitterRelations() {
        return twitterRelations;
    }


    public void setTwitterRelations(Set<GraphUser> twitterRelations) {
        this.twitterRelations = twitterRelations;
    }


    public Set<GraphUser> getContacts() {
        return contacts;
    }


    public void setContacts(Set<GraphUser> contacts) {
        this.contacts = contacts;
    }


    public Set<GraphUser> getKnows() {
        return knows;
    }


    public void setKnows(Set<GraphUser> knows) {
        this.knows = knows;
    }


    public Set<GraphUser> getBlocks() {
        return blocks;
    }


    public void setBlocks(Set<GraphUser> blocks) {
        this.blocks = blocks;
    }


    public Set<GraphUser> getFavorites() {
        return favorites;
    }


    public void setFavorites(Set<GraphUser> favorites) {
        this.favorites = favorites;
    }
}

我可能缺少什么?

谢谢你。

4

1 回答 1

0

两名嫌疑人

  1. 索引:我看到您有大约 5 个索引。当您有更多索引时,写入需要更长的时间,因为写入还应该更新索引作为事务的一部分。
  2. Eager Fetch:我看到您使用@Fetch 注释了大约 6 个关系。我相信 spring-data-neo4j 会在提交后尝试重新获取所有内容。如果这些关系/节点对它们自己的属性使用@Fetch 进行了注释,那么它们将被递归获取。

我建议您先删除 @Fetch 然后删除 @Index 来开始测试,看看这是否会提高性能。你也在做批量插入吗?

于 2013-08-13T16:17:00.700 回答