Re: [Neo4j] how many relationships?
An internal implementation would be probably faster. If timing is that critical for you, you can have a look in EmbeddedGraphDbImpl.getAllNodes() and implement a similar solution for relationships. Cheers Michael Am 23.07.2011 um 04:20 schrieb John cyuczieekc: Hey Jim, I am sort of glad to hear that, maybe in the future I could see a method like getAllRelationships(), or not, np :) Yes, using Michael's code works, but ... total relations count=100,011 timedelta=3,075,897,991 ns it kind of takes 3 seconds (when not cached) to count 100k relationships (considering there are 100k+2 unique nodes too) when cached: total relations count=100,011 timedelta=154,673,763 ns Still, it's pretty fast, but I have to wonder if it would be faster if using relationships directly :) Either way, wish y'all a great day! On Sat, Jul 23, 2011 at 3:57 AM, Jim Webber j...@neotechnology.com wrote: Hi John, Relationships are stored in a different store than nodes. This enables Neo4j to manage lifecycle events (like caching) for nodes and relationships separately. Neo4j really is a graph DB, not a triple store masquerading as a graph DB. Nonetheless, that code Michael sent still works :-) Jim ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
Hey Michael, I took a very quick look, I think understand it, looks like it attempts to get nodes by id starting from 0 until highest possible ID. public synchronized boolean hasNext() { while ( currentNode == null currentNodeId = highId ) { try { currentNode = getNodeById( currentNodeId++ ); } catch ( NotFoundException e ) { // ok we try next } } return currentNode != null; } (seems to work even for when neo4j recycles deleted ids; highId=100012 in my case where I had 100,011 relationships each with unique nodes, so likely 100,012 nodes) Thank you for pointing me to that, I will consider doing the same with getRelationshipById() and bench them both xD Done, looks like it halves the time when using getAllRels() ie. (output) counting inside the same transaction... Node `one` has 1,753,000 out rels, time=10,235,246,378 tx.finish() time=1,070,892,633 counting one's outgoing rels (outside of initial transaction)... Node `one` has 1,753,000 out rels, time=1,743,920,993 counting all outgoing rels of all nodes ... via getAllNodes all relationships in the database = 1,753,000 timedelta=26,404,843,957 ns counting all Relationships ... via getAllRels all relationships in the database = 1,753,000 timedelta=699,410,620 ns counting all outgoing rels of all nodes ... via getAllNodes all relationships in the database = 1,753,000 timedelta=1,667,748,552 ns counting all Relationships ... via getAllRels all relationships in the database = 1,753,000 timedelta=655,286,990 ns counting all outgoing rels of all nodes ... via getAllNodes all relationships in the database = 1,753,000 timedelta=*1,261*,898,459 ns counting all Relationships ... via getAllRels all relationships in the database = 1,753,000 timedelta=*663*,559,121 ns counting all outgoing rels of all nodes ... via getAllNodes all relationships in the database = 1,753,000 timedelta=1,257,557,629 ns counting all Relationships ... via getAllRels all relationships in the database = 1,753,000 timedelta=637,826,233 ns Shutting down database ... and the sample program for this(I did have to add getAllRels() which is similar with getAllNodes()): in EmbeddedGraphDbImpl.java public IterableRelationship getAllRels() { return new IterableRelationship() { @Override public IteratorRelationship iterator() { long highId = nodeManager.getHighestPossibleIdInUse( Relationship.class ); return new AllRelsIterator( highId ); } }; } private class AllRelsIterator implements IteratorRelationship { private final longhighId; private longcurrentRelId= 0; private RelationshipcurrentRel= null; AllRelsIterator( long highId ) { this.highId = highId; } @Override public synchronized boolean hasNext() { while ( currentRel == null currentRelId = highId ) { try { currentRel = getRelationshipById( currentRelId++ ); } catch ( NotFoundException e ) { // ok we try next } } return currentRel != null; } @Override public synchronized Relationship next() { if ( !hasNext() ) { throw new NoSuchElementException(); } Relationship nextNode = currentRel; currentRel = null; return nextNode; } @Override public void remove() { throw new UnsupportedOperationException(); } } -- /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import org.neo4j.kernel.*; public class CalculateShortestPath { private static final int SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns= 2 * 300; private static final intSHOWINFO_IF_REL_TOOK_MORE_THAN_ns = 3;
Re: [Neo4j] how many relationships?
Right, there could be even a faster ways but they would need a few additional methods in NodeManager :) Cheers Michael Am 23.07.2011 um 15:30 schrieb John cyuczieekc: Hey Michael, I took a very quick look, I think understand it, looks like it attempts to get nodes by id starting from 0 until highest possible ID. public synchronized boolean hasNext() { while ( currentNode == null currentNodeId = highId ) { try { currentNode = getNodeById( currentNodeId++ ); } catch ( NotFoundException e ) { // ok we try next } } return currentNode != null; } (seems to work even for when neo4j recycles deleted ids; highId=100012 in my case where I had 100,011 relationships each with unique nodes, so likely 100,012 nodes) Thank you for pointing me to that, I will consider doing the same with getRelationshipById() and bench them both xD Done, looks like it halves the time when using getAllRels() ie. (output) counting inside the same transaction... Node `one` has 1,753,000 out rels, time=10,235,246,378 tx.finish() time=1,070,892,633 counting one's outgoing rels (outside of initial transaction)... Node `one` has 1,753,000 out rels, time=1,743,920,993 counting all outgoing rels of all nodes ... via getAllNodes all relationships in the database = 1,753,000 timedelta=26,404,843,957 ns counting all Relationships ... via getAllRels all relationships in the database = 1,753,000 timedelta=699,410,620 ns counting all outgoing rels of all nodes ... via getAllNodes all relationships in the database = 1,753,000 timedelta=1,667,748,552 ns counting all Relationships ... via getAllRels all relationships in the database = 1,753,000 timedelta=655,286,990 ns counting all outgoing rels of all nodes ... via getAllNodes all relationships in the database = 1,753,000 timedelta=*1,261*,898,459 ns counting all Relationships ... via getAllRels all relationships in the database = 1,753,000 timedelta=*663*,559,121 ns counting all outgoing rels of all nodes ... via getAllNodes all relationships in the database = 1,753,000 timedelta=1,257,557,629 ns counting all Relationships ... via getAllRels all relationships in the database = 1,753,000 timedelta=637,826,233 ns Shutting down database ... and the sample program for this(I did have to add getAllRels() which is similar with getAllNodes()): in EmbeddedGraphDbImpl.java public IterableRelationship getAllRels() { return new IterableRelationship() { @Override public IteratorRelationship iterator() { long highId = nodeManager.getHighestPossibleIdInUse( Relationship.class ); return new AllRelsIterator( highId ); } }; } private class AllRelsIterator implements IteratorRelationship { private final longhighId; private longcurrentRelId= 0; private RelationshipcurrentRel= null; AllRelsIterator( long highId ) { this.highId = highId; } @Override public synchronized boolean hasNext() { while ( currentRel == null currentRelId = highId ) { try { currentRel = getRelationshipById( currentRelId++ ); } catch ( NotFoundException e ) { // ok we try next } } return currentRel != null; } @Override public synchronized Relationship next() { if ( !hasNext() ) { throw new NoSuchElementException(); } Relationship nextNode = currentRel; currentRel = null; return nextNode; } @Override public void remove() { throw new UnsupportedOperationException(); } } -- /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import
Re: [Neo4j] how many relationships?
thanks for that, I only had embedded-examples changed, but it looks like I was doing the git pull wrong, that is I was using `git fetch from upstream` instead of `git pull`... I actually never had to use this before :) I was only ever committing with git (used svn/mercurial before though) For some reason I remembered (from a friend) that fetch was the way to pull. So I did the git pull and it worked (the counting worked as expected too, hooray!). Thus my bad, soz :) I am glad I didn't have to wait 3 days, I even looked into Organizations on github as an alternative way of getting limited (read-only) access to the committers' repo. Now I can continue ... xD On Fri, Jul 22, 2011 at 7:51 AM, Michael Hunger michael.hun...@neotechnology.com wrote: github has no separate repo for the readonly url most probably your git pull failed due to local changes git stash them or use git pull --rebase Michael mobile mail please excuse brevity and typos Am 22.07.2011 um 04:32 schrieb cyuczi eekc cyuczie...@gmail.com: Hey, btw, the issue was fixed: https://trac.neo4j.org/ticket/356#comment:1 However, github didn't yet sync the git-readonly (ie. git:// github.com/neo4j/community.git ) and looks like I am 3-4 days back, since my HEAD is at: Minor fix to the cypher/identifiers section. https://github.com/neo4j/community/commit/dc260c269ae4e09362ada181d7b9a42e6c86560e nawroth https://github.com/nawroth (author) 3 days ago as seen here: https://github.com/neo4j/community/commits/master/ I guess that is why you didn't say anything yet (because me fetching from git would not be able to get the fix yet, 3 more days geezuz xD) Anyway, I'm only saying this just in case you were not aware this was fixed (apparently by someone else) and you were still working on it. Sorry, I already had made a ticket about this before you last replied. Thank you all, can't wait to test :) On Thu, Jul 21, 2011 at 12:13 PM, Michael Hunger michael.hun...@neotechnology.com wrote: We're already on it. Looking through the causes for that issue and will keep you and everyone else informed. Michael Am 21.07.2011 um 06:52 schrieb cyuczi eekc: about this, should I create an issue? ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
you would have never gotten the update git pull does a fetch and merge please read a quick intro to git there are many on the internets mobile mail please excuse brevity and typos Am 22.07.2011 um 08:10 schrieb cyuczi eekc cyuczie...@gmail.com: thanks for that, I only had embedded-examples changed, but it looks like I was doing the git pull wrong, that is I was using `git fetch from upstream` instead of `git pull`... I actually never had to use this before :) I was only ever committing with git (used svn/mercurial before though) For some reason I remembered (from a friend) that fetch was the way to pull. So I did the git pull and it worked (the counting worked as expected too, hooray!). Thus my bad, soz :) I am glad I didn't have to wait 3 days, I even looked into Organizations on github as an alternative way of getting limited (read-only) access to the committers' repo. Now I can continue ... xD On Fri, Jul 22, 2011 at 7:51 AM, Michael Hunger michael.hun...@neotechnology.com wrote: github has no separate repo for the readonly url most probably your git pull failed due to local changes git stash them or use git pull --rebase Michael mobile mail please excuse brevity and typos Am 22.07.2011 um 04:32 schrieb cyuczi eekc cyuczie...@gmail.com: Hey, btw, the issue was fixed: https://trac.neo4j.org/ticket/356#comment:1 However, github didn't yet sync the git-readonly (ie. git:// github.com/neo4j/community.git ) and looks like I am 3-4 days back, since my HEAD is at: Minor fix to the cypher/identifiers section. https://github.com/neo4j/community/commit/dc260c269ae4e09362ada181d7b9a42e6c86560e nawroth https://github.com/nawroth (author) 3 days ago as seen here: https://github.com/neo4j/community/commits/master/ I guess that is why you didn't say anything yet (because me fetching from git would not be able to get the fix yet, 3 more days geezuz xD) Anyway, I'm only saying this just in case you were not aware this was fixed (apparently by someone else) and you were still working on it. Sorry, I already had made a ticket about this before you last replied. Thank you all, can't wait to test :) On Thu, Jul 21, 2011 at 12:13 PM, Michael Hunger michael.hun...@neotechnology.com wrote: We're already on it. Looking through the causes for that issue and will keep you and everyone else informed. Michael Am 21.07.2011 um 06:52 schrieb cyuczi eekc: about this, should I create an issue? ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
How would I go about getting all relationships in the entire database ? (with neo4j embedded) I see there is an db.getAllNodes() for nodes is there something similar for relationships? On Wed, Jul 20, 2011 at 7:13 PM, cyuczi eekc cyuczie...@gmail.com wrote: Is there a way to get the number of relationships without having to iterate through (and count++) them? ie. rels=firstNode.getRelationships(); rels.size(); //doesn't actually exist ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
for (Node node : db.getAllNodes()) for (Relationship rel : node.getRelationships(Direction.OUTGOING)) { // your code here } Michael Am 22.07.2011 um 23:40 schrieb John cyuczieekc: How would I go about getting all relationships in the entire database ? (with neo4j embedded) I see there is an db.getAllNodes() for nodes is there something similar for relationships? On Wed, Jul 20, 2011 at 7:13 PM, cyuczi eekc cyuczie...@gmail.com wrote: Is there a way to get the number of relationships without having to iterate through (and count++) them? ie. rels=firstNode.getRelationships(); rels.size(); //doesn't actually exist ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
Though that is kind of telling me that relationships only exist in java as wrappers for an ordered tuple of nodes. I guess I was thinking that they were stored/accessed differently as unique objects(since they each have an id)... maybe they are but neo4j isn't exposing a method for parsing relationships directly, that is without going through a node first. The method you suggested seems like the long way to parse all relationships. Still, I will use it nonetheless ;) Thank you! On Fri, Jul 22, 2011 at 11:57 PM, Michael Hunger michael.hun...@neotechnology.com wrote: for (Node node : db.getAllNodes()) for (Relationship rel : node.getRelationships(Direction.OUTGOING)) { // your code here } Michael Am 22.07.2011 um 23:40 schrieb John cyuczieekc: How would I go about getting all relationships in the entire database ? (with neo4j embedded) I see there is an db.getAllNodes() for nodes is there something similar for relationships? On Wed, Jul 20, 2011 at 7:13 PM, cyuczi eekc cyuczie...@gmail.com wrote: Is there a way to get the number of relationships without having to iterate through (and count++) them? ie. rels=firstNode.getRelationships(); rels.size(); //doesn't actually exist ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
Hi John, Relationships are stored in a different store than nodes. This enables Neo4j to manage lifecycle events (like caching) for nodes and relationships separately. Neo4j really is a graph DB, not a tripple store masquerading as a graph DB. Nonetheless, that code Michael sent still works :-) Jim ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
Hey Jim, I am sort of glad to hear that, maybe in the future I could see a method like getAllRelationships(), or not, np :) Yes, using Michael's code works, but ... total relations count=100,011 timedelta=3,075,897,991 ns it kind of takes 3 seconds (when not cached) to count 100k relationships (considering there are 100k+2 unique nodes too) when cached: total relations count=100,011 timedelta=154,673,763 ns Still, it's pretty fast, but I have to wonder if it would be faster if using relationships directly :) Either way, wish y'all a great day! On Sat, Jul 23, 2011 at 3:57 AM, Jim Webber j...@neotechnology.com wrote: Hi John, Relationships are stored in a different store than nodes. This enables Neo4j to manage lifecycle events (like caching) for nodes and relationships separately. Neo4j really is a graph DB, not a triple store masquerading as a graph DB. Nonetheless, that code Michael sent still works :-) Jim ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
We're already on it. Looking through the causes for that issue and will keep you and everyone else informed. Michael Am 21.07.2011 um 06:52 schrieb cyuczi eekc: about this, should I create an issue? ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
Hey, btw, the issue was fixed: https://trac.neo4j.org/ticket/356#comment:1 However, github didn't yet sync the git-readonly (ie. git:// github.com/neo4j/community.git ) and looks like I am 3-4 days back, since my HEAD is at: Minor fix to the cypher/identifiers section. https://github.com/neo4j/community/commit/dc260c269ae4e09362ada181d7b9a42e6c86560e nawroth https://github.com/nawroth (author) 3 days ago as seen here: https://github.com/neo4j/community/commits/master/ I guess that is why you didn't say anything yet (because me fetching from git would not be able to get the fix yet, 3 more days geezuz xD) Anyway, I'm only saying this just in case you were not aware this was fixed (apparently by someone else) and you were still working on it. Sorry, I already had made a ticket about this before you last replied. Thank you all, can't wait to test :) On Thu, Jul 21, 2011 at 12:13 PM, Michael Hunger michael.hun...@neotechnology.com wrote: We're already on it. Looking through the causes for that issue and will keep you and everyone else informed. Michael Am 21.07.2011 um 06:52 schrieb cyuczi eekc: about this, should I create an issue? ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
github has no separate repo for tge readonly url most probably your git pull failed due to local changes git stash them or use git pull --rebase Michael mobile mail please excuse brevity and typos Am 22.07.2011 um 04:32 schrieb cyuczi eekc cyuczie...@gmail.com: Hey, btw, the issue was fixed: https://trac.neo4j.org/ticket/356#comment:1 However, github didn't yet sync the git-readonly (ie. git:// github.com/neo4j/community.git ) and looks like I am 3-4 days back, since my HEAD is at: Minor fix to the cypher/identifiers section. https://github.com/neo4j/community/commit/dc260c269ae4e09362ada181d7b9a42e6c86560e nawroth https://github.com/nawroth (author) 3 days ago as seen here: https://github.com/neo4j/community/commits/master/ I guess that is why you didn't say anything yet (because me fetching from git would not be able to get the fix yet, 3 more days geezuz xD) Anyway, I'm only saying this just in case you were not aware this was fixed (apparently by someone else) and you were still working on it. Sorry, I already had made a ticket about this before you last replied. Thank you all, can't wait to test :) On Thu, Jul 21, 2011 at 12:13 PM, Michael Hunger michael.hun...@neotechnology.com wrote: We're already on it. Looking through the causes for that issue and will keep you and everyone else informed. Michael Am 21.07.2011 um 06:52 schrieb cyuczi eekc: about this, should I create an issue? ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
Hi, Responses from calling the Neo4j APIs are typically lazy, for performance reasons. So there's no way of eagerly counting the number of relationships unless you force eager evaluation as you've suggested below. Jim On 20 Jul 2011, at 11:13, cyuczi eekc wrote: Is there a way to get the number of relationships without having to iterate through (and count++) them? ie. rels=firstNode.getRelationships(); rels.size(); //doesn't actually exist ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
I guess I was hoping it(size/count) was cached in the database or the underlaying database would provide this somehow, ie. in berkeleydb (java edition) there's a cursor.count() I could use (though I don't know how they did it implementation-wise) Thanks! I needed to know that. On Wed, Jul 20, 2011 at 8:37 PM, Jim Webber j...@neotechnology.com wrote: Hi, Responses from calling the Neo4j APIs are typically lazy, for performance reasons. So there's no way of eagerly counting the number of relationships unless you force eager evaluation as you've suggested below. Jim On 20 Jul 2011, at 11:13, cyuczi eekc wrote: Is there a way to get the number of relationships without having to iterate through (and count++) them? ie. rels=firstNode.getRelationships(); rels.size(); //doesn't actually exist ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
Caching that result would require synchronizing it with every change using up memory and performance (at every change) for something that can be computed So far it has not been worth the effort. If you really need that value very often you could write a small TransactionEventHandler that keeps the count updated for the nodes you're interested in. You would then ask this handler for the Rel-Count of a node, which would either compute it (and add/register it to its cache) or just return it from the cache. Michael Am 20.07.2011 um 21:50 schrieb cyuczi eekc: I guess I was hoping it(size/count) was cached in the database or the underlaying database would provide this somehow, ie. in berkeleydb (java edition) there's a cursor.count() I could use (though I don't know how they did it implementation-wise) Thanks! I needed to know that. On Wed, Jul 20, 2011 at 8:37 PM, Jim Webber j...@neotechnology.com wrote: Hi, Responses from calling the Neo4j APIs are typically lazy, for performance reasons. So there's no way of eagerly counting the number of relationships unless you force eager evaluation as you've suggested below. Jim On 20 Jul 2011, at 11:13, cyuczi eekc wrote: Is there a way to get the number of relationships without having to iterate through (and count++) them? ie. rels=firstNode.getRelationships(); rels.size(); //doesn't actually exist ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
Trying to count the relationships the normal way I find that oddly, I cannot see more than 100+x relationships, where x is the maximum number of relations ever added within a transaction. For example, if I add 91 relationships in a transation, and I count them, I have 91. I run the program again and I have 182, then I run the program again and I count 191, and any subsequent program runs will have the same 191 count. Is this a bug or am I missing something very important ?! Here's the sample code to try (run it 3 times and observe the ante-ante-last line on console: Node `one` has 191 out rels, time=24,098,904): (I don't know how I would place this code into a code block though) /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import org.neo4j.kernel.*; public class CalculateShortestPath { private static final int SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns= 2 * 300; private static final intSHOWINFO_IF_REL_TOOK_MORE_THAN_ns = 3; private static final intSHOWEVERY_xTH_REL = 1; private static final intHOWMANY_RELATIONSHIPS = 91; private static final StringDB_PATH = neo4j-shortest-path; private static final StringNAME_KEY = name; private static RelationshipTypeKNOWS = DynamicRelationshipType .withName( KNOWS ); private static GraphDatabaseServicegraphDb; private static IndexNodeindexService; private static DecimalFormatcommaDelimitedFormatter = new DecimalFormat( ###,### ); public static String number( double val ) { return commaDelimitedFormatter.format( val ); } public static String getTimeDelta( long start, long end ) { return commaDelimitedFormatter.format( end - start ); } public static void main( final String[] args ) { // deleteFileOrDirectory( new File( DB_PATH ) );// XXX: graphDb = new EmbeddedGraphDatabase( DB_PATH ); indexService = graphDb.index().forNodes( nodes ); registerShutdownHook(); Transaction tx = graphDb.beginTx(); try { Node one = getOrCreateNode( one ); DynamicRelationshipType moo = DynamicRelationshipType.withName( moo ); for ( int i = 1; i = HOWMANY_RELATIONSHIPS; i++ ) { long start = System.nanoTime(); Relationship rel = one.createRelationshipTo( graphDb.createNode(), moo ); rel.setProperty( relname, i ); long end = System.nanoTime(); if ( ( i % SHOWEVERY_xTH_REL == 0 ) || ( end - start SHOWINFO_IF_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( i ) + timeDelta= + number( end - start ) ); } } System.out.println( counting... ); long start = System.nanoTime(); IterableRelationship rel = one.getRelationships( Direction.OUTGOING, moo ); long count = 0; long tstart = 0; for ( Relationship relationship : rel ) { long tend = System.nanoTime(); count++; if ( ( tend - tstart SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( count ) + timeDelta= + number( tend - tstart ) ); } tstart = System.nanoTime(); } long end = System.nanoTime(); System.out.println( Node ` + one.getProperty( NAME_KEY ) + ` has + number( count ) + out rels, time= + number( end - start ) ); // /* // * (Neo) -- (Trinity) // * \ ^ // * v / // * (Morpheus) -- (Cypher) // * \ | // * v v // * (Agent Smith) // */ // createChain( Neo, Trinity ); // createChain( Neo, Morpheus, Trinity ); // createChain( Morpheus, Cypher, Agent Smith ); // createChain( Morpheus, Agent Smith );
Re: [Neo4j] how many relationships?
I should probably mention that I am using neo4j community (embedded) latest sources up to date from github On Thu, Jul 21, 2011 at 4:59 AM, cyuczi eekc cyuczie...@gmail.com wrote: Trying to count the relationships the normal way I find that oddly, I cannot see more than 100+x relationships, where x is the maximum number of relations ever added within a transaction. For example, if I add 91 relationships in a transation, and I count them, I have 91. I run the program again and I have 182, then I run the program again and I count 191, and any subsequent program runs will have the same 191 count. Is this a bug or am I missing something very important ?! Here's the sample code to try (run it 3 times and observe the ante-ante-last line on console: Node `one` has 191 out rels, time=24,098,904): (I don't know how I would place this code into a code block though) /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import org.neo4j.kernel.*; public class CalculateShortestPath { private static final int SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns= 2 * 300; private static final int SHOWINFO_IF_REL_TOOK_MORE_THAN_ns= 3; private static final intSHOWEVERY_xTH_REL = 1; private static final intHOWMANY_RELATIONSHIPS = 91; private static final StringDB_PATH = neo4j-shortest-path; private static final StringNAME_KEY = name; private static RelationshipTypeKNOWS = DynamicRelationshipType .withName( KNOWS ); private static GraphDatabaseServicegraphDb; private static IndexNodeindexService; private static DecimalFormatcommaDelimitedFormatter = new DecimalFormat( ###,### ); public static String number( double val ) { return commaDelimitedFormatter.format( val ); } public static String getTimeDelta( long start, long end ) { return commaDelimitedFormatter.format( end - start ); } public static void main( final String[] args ) { // deleteFileOrDirectory( new File( DB_PATH ) );// XXX: graphDb = new EmbeddedGraphDatabase( DB_PATH ); indexService = graphDb.index().forNodes( nodes ); registerShutdownHook(); Transaction tx = graphDb.beginTx(); try { Node one = getOrCreateNode( one ); DynamicRelationshipType moo = DynamicRelationshipType.withName( moo ); for ( int i = 1; i = HOWMANY_RELATIONSHIPS; i++ ) { long start = System.nanoTime(); Relationship rel = one.createRelationshipTo( graphDb.createNode(), moo ); rel.setProperty( relname, i ); long end = System.nanoTime(); if ( ( i % SHOWEVERY_xTH_REL == 0 ) || ( end - start SHOWINFO_IF_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( i ) + timeDelta= + number( end - start ) ); } } System.out.println( counting... ); long start = System.nanoTime(); IterableRelationship rel = one.getRelationships( Direction.OUTGOING, moo ); long count = 0; long tstart = 0; for ( Relationship relationship : rel ) { long tend = System.nanoTime(); count++; if ( ( tend - tstart SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( count ) + timeDelta= + number( tend - tstart ) ); } tstart = System.nanoTime(); } long end = System.nanoTime(); System.out.println( Node ` + one.getProperty( NAME_KEY ) + ` has + number( count ) + out rels, time= + number( end - start ) ); // /* // * (Neo) -- (Trinity) // * \ ^ // * v / // * (Morpheus) -- (Cypher) // * \ |
Re: [Neo4j] how many relationships?
Ok there, I found out something new, if I do the count outside of the transaction (ie. after tx.finish() ) then it works right, ie. in a different example: Node `one` has 100,100 out rels, time=7,954,653,001 tx.finish() time=1,525,669,261 Node `one` has 1,200,546 out rels And as long as I create relationships inside the transaction, it will always show me(when I count) the number of added relationships + 100, even if on previous program run I had a transaction with more added relationships (ie. 200,000 as opposed to 100,000 now = shows 100,100) ok, here's the latest sample program: with this output ie. Node `one` has 99,100 out rels, time=9,265,459,688 tx.finish() time=1,221,787,378 counting outside of transaction... Node `one` has 1,399,546 out rels, time=353,716,303 /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import org.neo4j.kernel.*; public class CalculateShortestPath { private static final int SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns= 2 * 300; private static final intSHOWINFO_IF_REL_TOOK_MORE_THAN_ns = 3; private static final intSHOWEVERY_xTH_REL = 1; private static final intHOWMANY_RELATIONSHIPS = 99000; private static final StringDB_PATH = neo4j-shortest-path; private static final StringNAME_KEY = name; private static RelationshipTypeKNOWS = DynamicRelationshipType .withName( KNOWS ); private static GraphDatabaseServicegraphDb; private static IndexNodeindexService; private static DecimalFormatcommaDelimitedFormatter = new DecimalFormat( ###,### ); public static String number( double val ) { return commaDelimitedFormatter.format( val ); } public static void main( final String[] args ) { // deleteFileOrDirectory( new File( DB_PATH ) );// XXX: graphDb = new EmbeddedGraphDatabase( DB_PATH ); indexService = graphDb.index().forNodes( nodes ); registerShutdownHook(); Transaction tx = graphDb.beginTx(); Node one = getOrCreateNode( one ); DynamicRelationshipType moo = DynamicRelationshipType.withName( moo ); try { for ( int i = 1; i = HOWMANY_RELATIONSHIPS; i++ ) { long start = System.nanoTime(); Relationship rel = one.createRelationshipTo( graphDb.createNode(), moo ); // rel.setProperty( relname, i ); long end = System.nanoTime(); if ( ( i % SHOWEVERY_xTH_REL == 0 ) || ( end - start SHOWINFO_IF_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( i ) + timeDelta= + number( end - start ) ); } } System.out.println( counting... ); long start = System.nanoTime(); IterableRelationship rel = one.getRelationships( Direction.OUTGOING, moo ); long count = 0; long tstart = 0; for ( Relationship relationship : rel ) { long tend = System.nanoTime(); count++; if ( ( tend - tstart SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( count ) + timeDelta= + number( tend - tstart ) ); } tstart = System.nanoTime(); } long end = System.nanoTime(); System.out.println( Node ` + one.getProperty( NAME_KEY ) + ` has + number( count ) + out rels, time= + number( end - start ) ); // /* // * (Neo) -- (Trinity) // * \ ^ // * v / // * (Morpheus) -- (Cypher) // * \ | // * v v // * (Agent Smith) // */ // createChain( Neo, Trinity ); // createChain( Neo, Morpheus, Trinity ); // createChain( Morpheus, Cypher, Agent Smith ); // createChain( Morpheus, Agent Smith ); tx.success(); } finally {
Re: [Neo4j] how many relationships?
about this, should I create an issue? On Thu, Jul 21, 2011 at 5:15 AM, cyuczi eekc cyuczie...@gmail.com wrote: Ok there, I found out something new, if I do the count outside of the transaction (ie. after tx.finish() ) then it works right, ie. in a different example: Node `one` has 100,100 out rels, time=7,954,653,001 tx.finish() time=1,525,669,261 Node `one` has 1,200,546 out rels And as long as I create relationships inside the transaction, it will always show me(when I count) the number of added relationships + 100, even if on previous program run I had a transaction with more added relationships (ie. 200,000 as opposed to 100,000 now = shows 100,100) ok, here's the latest sample program: with this output ie. Node `one` has 99,100 out rels, time=9,265,459,688 tx.finish() time=1,221,787,378 counting outside of transaction... Node `one` has 1,399,546 out rels, time=353,716,303 /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import org.neo4j.kernel.*; public class CalculateShortestPath { private static final int SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns= 2 * 300; private static final int SHOWINFO_IF_REL_TOOK_MORE_THAN_ns= 3; private static final intSHOWEVERY_xTH_REL = 1; private static final intHOWMANY_RELATIONSHIPS = 99000; private static final StringDB_PATH = neo4j-shortest-path; private static final StringNAME_KEY = name; private static RelationshipTypeKNOWS = DynamicRelationshipType .withName( KNOWS ); private static GraphDatabaseServicegraphDb; private static IndexNodeindexService; private static DecimalFormatcommaDelimitedFormatter = new DecimalFormat( ###,### ); public static String number( double val ) { return commaDelimitedFormatter.format( val ); } public static void main( final String[] args ) { // deleteFileOrDirectory( new File( DB_PATH ) );// XXX: graphDb = new EmbeddedGraphDatabase( DB_PATH ); indexService = graphDb.index().forNodes( nodes ); registerShutdownHook(); Transaction tx = graphDb.beginTx(); Node one = getOrCreateNode( one ); DynamicRelationshipType moo = DynamicRelationshipType.withName( moo ); try { for ( int i = 1; i = HOWMANY_RELATIONSHIPS; i++ ) { long start = System.nanoTime(); Relationship rel = one.createRelationshipTo( graphDb.createNode(), moo ); // rel.setProperty( relname, i ); long end = System.nanoTime(); if ( ( i % SHOWEVERY_xTH_REL == 0 ) || ( end - start SHOWINFO_IF_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( i ) + timeDelta= + number( end - start ) ); } } System.out.println( counting... ); long start = System.nanoTime(); IterableRelationship rel = one.getRelationships( Direction.OUTGOING, moo ); long count = 0; long tstart = 0; for ( Relationship relationship : rel ) { long tend = System.nanoTime(); count++; if ( ( tend - tstart SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( count ) + timeDelta= + number( tend - tstart ) ); } tstart = System.nanoTime(); } long end = System.nanoTime(); System.out.println( Node ` + one.getProperty( NAME_KEY ) + ` has + number( count ) + out rels, time= + number( end - start ) ); // /* // * (Neo) -- (Trinity) // * \ ^ // * v / // * (Morpheus) -- (Cypher) // * \ | // * v v // * (Agent Smith) // */ // createChain( Neo,