Add relation in existing node

64 views
Skip to first unread message

Navrattan Yadav

unread,
Jan 3, 2014, 8:09:23 AM1/3/14
to ne...@googlegroups.com
Hi ...
     Currently we have 1.5 million node and one relation : KNOW between them.  

    Basic Model is : when a user register we add KNOW relation to all his friends.  (friends are :phone book friends)

    Now its getting slow as user increase. so we want to add more relation based on : COUNTRY,  SOCIAL NETWORK, CITY, COLLEGE ETC.

   so we need to add these relation in existing node without blocking database by running a separate thread.

  Please suggest some way,some query . how we can do this....


Michael Hunger

unread,
Jan 3, 2014, 8:27:30 AM1/3/14
to ne...@googlegroups.com
You have to share more details.

what versions do you use
what is your stack
what APIs do you use
share the code to create the relationships
what is getting slow
how many concurrent users do you have

etc.

Sometimes a slowdown is related to doing just one single update per transaction and having millions of those tiny transactions.
So it makes sense to aggregate those changes into larger chunks, e.g. all create your knows relationships in one TX (and the other ones too).

Perhaps something that might help you: http://maxdemarzi.com/2013/09/05/scaling-writes/

Michael
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Navrattan Yadav

unread,
Jan 3, 2014, 8:45:30 AM1/3/14
to Neo4J
Neo4j version  :  2.0.0-M06 .
Operating System : linux
Ram : 4GB
 
sir we get slow when we get 2nd degree friends for a user.Then most of People Suggest to create more relation :
So we are creating more relation to make it faster.

Code for creating relation : Using Java API :

public void addFriend(Person otherPerson) {
if (!this.equals(otherPerson)) {

                        //check if already created

Relationship friendRel = getFriendRelationshipTo(otherPerson);

if (friendRel == null) {

underlyingNode.createRelationshipTo( otherPerson.getUnderlyingNode(), KNOW);
}
}
}


private Relationship getFriendRelationshipTo(Person otherPerson) {
Node otherNode = otherPerson.getUnderlyingNode();
for (Relationship rel : underlyingNode.getRelationships(Direction.OUTGOING,KNOW)) {
if (rel.getOtherNode(underlyingNode).equals(otherNode)) {
return rel;
}
}
return null;
}




--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/Q_RkuWN_biw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Thanks and Regards

Navrattan Yadav

Michael Hunger

unread,
Jan 3, 2014, 9:19:03 AM1/3/14
to ne...@googlegroups.com
How many knows relationships do you have per person?

I think you should also check your configuration, 4GB of RAM is a bit on the low side, you might end up using swap all the time.
You should have enough non-heap RAM for some decent memory mapping of your store-files
And enough heap for sensible high level caches (e.g. 4G-8G HEAP)
So in total a machine with 16-32G heap would make more sense.

Also Upgrade to Neo4j 2.0 to have a stable baseline.


And if you add many friends at once I would do all those rel-checks at once too, so instead of iterating over all rels 100 times and checking them against a single person.

You iterate over them once and remove already existing friends from a hashset.

something like:

Set<Node> filterNewFriends(Set<Node> potentialFriends, Node underlyingNode) {
for (Relationship rel : underlyingNode.getRelationships(Direction.OUTGOING,KNOW)) {
potentialFriends.remove(rel.getEndNode());
}
return potentialFriends;
}

and then only create relationships to all those friends that have been returned.
Reply all
Reply to author
Forward
0 new messages