I am trying to benchmark three different graph database the Titan, the OrientDB and the Neo4j. I want to measure the execution time for the database creation. As a test case I use this dataset http://snap.stanford.edu/data/web-flickr.html . Although the data are stored locally I and not in the computers memory I have noticed it is consumed a lot of memory and unfortunately after a while eclipse crashes. Why is this happening?
Here's some code snippets: Titan graph creation
public long createGraphDB(String datasetRoot, TitanGraph titanGraph) {
long duration;
long startTime = System.nanoTime();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(datasetRoot)));
String line;
int lineCounter = 1;
while((line = reader.readLine()) != null) {
if(lineCounter > 4) {
String[] parts = line.split(" ");
Vertex srcVertex = titanGraph.addVertex(null);
srcVertex.setProperty( "nodeId", parts[0] );
Vertex dstVertex = titanGraph.addVertex(null);
dstVertex.setProperty( "nodeId", parts[1] );
Edge edge = titanGraph.addEdge(null, srcVertex, dstVertex, "similar");
titanGraph.commit();
}
lineCounter++;
}
reader.close();
}
catch(IOException ioe) {
ioe.printStackTrace();
}
catch( Exception e ) {
titanGraph.rollback();
}
long endTime = System.nanoTime();
duration = endTime - startTime;
return duration;
}
OrientDB graph creation:
public long createGraphDB(String datasetRoot, OrientGraph orientGraph) {
long duration;
long startTime = System.nanoTime();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(datasetRoot)));
String line;
int lineCounter = 1;
while((line = reader.readLine()) != null) {
if(lineCounter > 4) {
String[] parts = line.split(" ");
Vertex srcVertex = orientGraph.addVertex(null);
srcVertex.setProperty( "nodeId", parts[0] );
Vertex dstVertex = orientGraph.addVertex(null);
dstVertex.setProperty( "nodeId", parts[1] );
Edge edge = orientGraph.addEdge(null, srcVertex, dstVertex, "similar");
orientGraph.commit();
}
lineCounter++;
}
reader.close();
}
catch(IOException ioe) {
ioe.printStackTrace();
}
catch( Exception e ) {
orientGraph.rollback();
}
long endTime = System.nanoTime();
duration = endTime - startTime;
return duration;
Neo4j graph creation:
public long createDB(String datasetRoot, GraphDatabaseService neo4jGraph) {
long duration;
long startTime = System.nanoTime();
Transaction tx = neo4jGraph.beginTx();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(datasetRoot)));
String line;
int lineCounter = 1;
while((line = reader.readLine()) != null) {
if(lineCounter > 4) {
String[] parts = line.split(" ");
Node srcNode = neo4jGraph.createNode();
srcNode.setProperty("nodeId", parts[0]);
Node dstNode = neo4jGraph.createNode();
dstNode.setProperty("nodeId", parts[1]);
Relationship relationship = srcNode.createRelationshipTo(dstNode, RelTypes.SIMILAR);
}
lineCounter++;
}
tx.success();
reader.close();
}
catch (IOException e) {
e.printStackTrace();
}
finally {
tx.finish();
}
long endTime = System.nanoTime();
duration = endTime - startTime;
return duration;
}
EDIT: I tried the BatchGraph solution and it seems that it will run forever. It run the whole night yesterday and it never came to an end. I had to stop it. Is there anything wrong in my code?
TitanGraph graph = TitanFactory.open("data/titan");
BatchGraph<TitanGraph> batchGraph = new BatchGraph<TitanGraph>(graph, VertexIDType.STRING, 1000);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("data/flickrEdges.txt")));
String line;
int lineCounter = 1;
while((line = reader.readLine()) != null) {
if(lineCounter > 4) {
String[] parts = line.split(" ");
Vertex srcVertex = batchGraph.getVertex(parts[0]);
if(srcVertex == null) {
srcVertex = batchGraph.addVertex(parts[0]);
}
Vertex dstVertex = batchGraph.getVertex(parts[1]);
if(dstVertex == null) {
dstVertex = batchGraph.addVertex(parts[1]);
}
Edge edge = batchGraph.addEdge(null, srcVertex, dstVertex, "similar");
batchGraph.commit();
}
lineCounter++;
}
reader.close();
}