我正在使用2.0.1版本。
我有成千上万个需要插入的节点。我的neo4j图形数据库在独立服务器上,并且我正在使用neo4j rest图形数据库库通过RestApi来实现这一点。
然而,我面临着缓慢的性能结果。我将我的查询分成批处理,每次发送500个cypher语句的单个http调用。我得到的结果是:
10:38:10.984 INFO commit
10:38:13.161 INFO commit
10:38:13.277 INFO commit
10:38:15.132 INFO commit
10:38:15.218 INFO commit
10:38:17.288 INFO commit
10:38:19.488 INFO commit
10:38:22.020 INFO commit
10:38:24.806 INFO commit
10:38:27.848 INFO commit
10:38:31.172 INFO commit
10:38:34.767 INFO commit
10:38:38.661 INFO commit
等等。 我正在使用的查询如下:
MERGE (a{main:{val1},prop2:{val2}}) MERGE (b{main:{val3}}) CREATE UNIQUE (a)-[r:relationshipname]-(b);
我的代码是这样的:
private RestAPI restAPI;
private RestCypherQueryEngine engine;
private GraphDatabaseService graphDB = new RestGraphDatabase("http://localdomain.com:7474/db/data/");
...
restAPI = ((RestGraphDatabase) graphDB).getRestAPI();
engine = new RestCypherQueryEngine(restAPI);
...
Transaction tx = graphDB.getRestAPI().beginTx();
try {
int ctr = 0;
while (isExists) {
ctr++;
//excute query here through engine.query()
if (ctr % 500 == 0) {
tx.success();
tx.close();
tx = graphDB.getRestAPI().beginTx();
LOGGER.info("commit");
}
}
tx.success();
} catch (FileNotFoundException | NumberFormatException | ArrayIndexOutOfBoundsException e) {
tx.failure();
} finally {
tx.close();
}
谢谢!
更新基准。 抱歉造成困扰,我发布的基准不准确,并且不适用于500个查询。我ctr变量实际上并不是指cypher查询的数量。
所以现在,我每3秒钟有500个查询,而且这3秒钟还在不断增加。与嵌入式Neo4j相比,速度仍然非常慢。