【问题标题】:Slowness observed in obtaining connection using neo4j java jdbc driver使用 neo4j java jdbc 驱动程序获取连接时观察到缓慢
【发布时间】:2019-05-27 18:36:15
【问题描述】:

我的 java 应用程序部署在 websphere 应用程序服务器中。我成功地能够使用 jdbc 驱动程序从我的 java 应用程序连接到 neo4j。但是我遵循的方法存在一些性能问题。目前 neo4j 服务器在 Xms - 8G 和 Xmx-16GB 上运行。我的数据量较少,大约 40mb,有 3100 个节点。当我们使用 cypher 测试 http 的性能时,性能非常出色。但在 java 应用程序中,我们使用 jdbc 驱动程序通过 bolt 连接到 neo4j。每个连接创建大约需要 100 毫秒,这会增加延迟。使用这种方法和 500 个并发请求,我们只能达到 160 次/秒。有 500 个并发调用,请求正在排队,响应时间快到 3 秒。任何改进的指针都会有所帮助。 (应用和neo4j在同一个VLAN下的不同物理服务器上)。

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

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

【问题讨论】:

    标签: neo4j websphere datasource


    【解决方案1】:

    如果您使用DriverManager.getConnection(),您将绕过 WebSphere 连接池,因为您在此处直接从 JDBC 驱动程序获取连接。

    为了提高性能,我推荐configuring a DataSource using the admin console,然后更新您的应用程序以从数据源而不是直接从驱动程序获取连接。这样,WebSphere 将汇集连接,您可能会获得更好的性能。

    编辑: Gas 在 cmets 中指出 Neo4j 不提供 DataSource 实现。要解决这个问题,您可以实现一个像这样的简单方法:

    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,那么您可以configure a DataSource 而无需编写自己的数据源。

    【讨论】:

    • 我尝试在 websphere 中添加数据源。即使多次尝试都失败了,是否有任何可用的步骤序列?
    • 是的,我的回答中链接了步骤顺序。具体在这里:ibm.com/support/knowledgecenter/en/SSAW57_9.0.0/…
    • 我尝试了以下步骤。但得到以下错误。 DataSource 类不能作为一阶段使用:ClassCastException: org.neo4j.jdbc.Driver incompatible with javax.sql.ConnectionPoolDataSource
    • @AndyGuibert Neo4j 不兼容 JDBC 并且没有实现 DataSource 接口,因此无法在 WAS 中配置。 OP 必须在他的应用程序中实现池化。
    • 好点@Gas,我已经用可能的解决方法更新了我的答案
    猜你喜欢
    • 1970-01-01
    • 2014-07-28
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    相关资源
    最近更新 更多