我正在尝试对三个不同的图形数据库Titan、OrientDB和Neo4j进行基准测试。我想测量数据库创建的执行时间。作为测试用例,我使用这个数据集http://snap.stanford.edu/data/web-flickr.html。尽管数据存储在本地而不是计算机内存中,但我注意到它消耗了很多内存,不幸的是,过了一会儿 eclipse 崩溃了。为什么会这样?
以下是一些代码片段: Titan 图创建
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 图创建:
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 图创建:
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;
}
编辑:我尝试了 BatchGraph 解决方案,似乎它将永远运行。它昨天运行了一整夜,从未结束。我不得不阻止它。我的代码有什么问题吗?
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();
}