【问题标题】:How to improve the performance of neo4j-jdbc-driver?如何提高neo4j-jdbc-driver的性能?
【发布时间】:2014-07-18 04:04:51
【问题描述】:

如何提高 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();

【问题讨论】:

    标签: java performance neo4j


    【解决方案1】:

    在你的程序中只做一次,然后传递连接。

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

    【讨论】:

    • 有没有办法实现连接池?由于会有很多用户,不可能只建立一个连接。
    • 我发现了一个有趣的事情,当我使用osx中的eclipse连接redhat中的neo4j服务器时,只需要一秒钟就可以得到结果。但是当我在 windows 中使用 eclipse 时,需要花费超过 6 秒才能得到结果。代码是一样的...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多