使用Neo4j Java JDBC驱动程序获得连接时观察到速度慢 [英] Slowness observed in obtaining connection using neo4j java jdbc driver

查看:494
本文介绍了使用Neo4j Java JDBC驱动程序获得连接时观察到速度慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Java应用程序部署在Websphere应用程序服务器中.我可以使用jdbc驱动程序从Java应用程序成功连接到neo4j.但是我遵循的方法存在一些性能问题.当前neo4j服务器正在Xms-8G和Xmx-16GB上运行.我拥有3100个节点的aprox 40mb数据量较少.当我们使用cypher在http上测试性能时,性能非常出色.但是在Java应用程序中,我们使用jdbc驱动程序通过螺栓连接到neo4j.每个连接创建大约需要100毫秒,这会增加延迟.使用500个并发请求的这种方法,我们只能实现160次命中/秒.通过500个并发呼叫,请求正在排队,响应时间缩短到3秒.任何改进的指示将是有帮助的. (Application和neo4j在同一VLAN下的不同物理服务器上.)

I have my java application deployed in websphere application server. I am successfully able to connect to neo4j from my java application using jdbc driver. But there are some performance issues with the approach i have followed. Currently neo4j server is running on Xms - 8G and Xmx-16GB. I have less amount of data that is aprox 40mb with 3100 nodes. When we test the performance over http with cypher, the performance is outstanding. But in the java application we are using the jdbc driver to connect to neo4j via bolt. Every connection creation is taking around 100ms which is adding up delay. We are able to achieve only 160 hits/sec with this approach with 500 concurrent requests. With 500 concurrent calls, the requests are queuing up and the response time is shooting to 3 seconds. Any pointers of improvement would be helpful. (Application and neo4j are on different physical servers under the same VLAN).

用于创建连接的代码如下.

Code used to create connection is below.

Class.forName("org.neo4j.jdbc.Driver").newInstance(); 连接conn = DriverManager.getConnection("jdbc:neo4j:bolt://localhost:port");

Class.forName("org.neo4j.jdbc.Driver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:neo4j:bolt://localhost:port") ;

推荐答案

如果执行DriverManager.getConnection(),则绕过WebSphere连接池,因为您是从此处直接从JDBC驱动程序获得连接的.

If you do DriverManager.getConnection() you are bypassing the WebSphere connection pool since you are getting connections directly from the JDBC driver here.

为提高性能,我建议

To improve performance, I recommend configuring a DataSource using the admin console, and then updating your application to get connections from the DataSource instead of directly from the driver. This way, connections will be pooled by WebSphere and you will likely get much better performance.

Gas在评论中指出Neo4j不提供DataSource实现.要解决此问题,您可以实现一个简单的如下所示:

Gas pointed out in the comments that Neo4j does not provide a DataSource implementation. To work around this, you can implement a simple one like this:

public class Neo4jDataSource implements javax.sql.DataSource {

    private PrintWriter pw;

    @Override
    public Connection getConnection() throws SQLException {
        return DriverManager.getConnection("jdbc:neo4j:bolt://localhost:port");
    }

    @Override
    public Connection getConnection(String username, String password) throws SQLException {
        // change URL here if you want to authenticate differently for different
        // user/pass combos
        return DriverManager.getConnection("jdbc:neo4j:bolt://localhost:port");
    }

    @Override
    public PrintWriter getLogWriter() throws SQLException {
        return pw;
    }

    @Override
    public void setLogWriter(PrintWriter out) throws SQLException {
        pw = out;
    }

    @Override
    public void setLoginTimeout(int seconds) throws SQLException {
    }

    @Override
    public int getLoginTimeout() throws SQLException {
        return 0;
    }

    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        throw new SQLFeatureNotSupportedException();
    }

    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {
        throw new SQLFeatureNotSupportedException();
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        return false;
    }
}

或者,如果您切换到WebSphere Liberty,则可以

Alternatively, if you switch to WebSphere Liberty, then you can configure a DataSource without needing to write your own DataSource.

这篇关于使用Neo4j Java JDBC驱动程序获得连接时观察到速度慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆