如何提高neo4j-jdbc-driver的性能?

时间:2014-07-18 04:04:52

标签: java performance neo4j

我怎样才能提高neo4j-jdbc-driver的性能?我使用MVC结构来实现我的代码。构建Apache HTTP客户端似乎花费了大约3~5秒,所以我认为最好的方法是减少http连接。但为什么下面的代码会三次“启动Apache HTTP客户端”?,我想我只建立一次http连接。

控制台日志

Starting the Apache HTTP client
Starting the Apache HTTP client
->Columns: [node] current row -1: null
Starting the Apache HTTP client
Stopping the HTTP client

Neo4jServiceTester.java

@Test
public void findNodeTester() {
    try {
        String UUID = "306C0F88-0A26-41EA-A954-DFC7025402DC";
        neo4jService.findNode(UUID);
    } catch(Exception e) {
        e.printStackTrace();
    }
}

Neo4jService.java

public void findNode(String UUID) throws Exception {
    Neo4jConnection connection = new Driver().connect("jdbc:neo4j://172.11.13.23:7474?debug=true", new Properties());
    connection.setAutoCommit(false);
    NodeBean node;
    try {
        node = neo4jDAO.findNode(connection, UUID);
        System.out.println("node=" + node.toString());
        connection.commit();
    } catch(Exception e) {
        connection.rollback();
        e.printStackTrace();
    }
    connection.close(); 
}

BaseNeo4jDAO.java

public NodeBean findNode(Neo4jConnection connection, String UUID) throws Exception {
    String queryStr = "MATCH (n) WHERE n.UUID = \"" + UUID + "\" RETURN { id : ID(n), labels : labels(n), properties: n } as node";
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery(queryStr); 
    rs.next();
    NodeBean node = new NodeBean();
    BeanUtils.populate(node, (Map<String, Object>) rs.getObject("node"));
    return node;
}

更新

在以下情况下似乎打印“启动Apache HTTP客户端”:

1. Neo4jConnection connection = neo4jDB.getConnection();
2. ResultSet rs = stmt.executeQuery(queryStr);
3. connection.commit();

1 个答案:

答案 0 :(得分:0)

在程序中只执行一次,然后传递连接。

Neo4jConnection connection = new Driver().connect("jdbc:neo4j://172.11.13.23:7474?debug=true", new Properties());
connection.setAutoCommit(false);