kamathsachin7
kamathsachin7

Reputation: 9

Slowness observed in obtaining connection using neo4j java jdbc driver

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(); Connection conn = DriverManager.getConnection("jdbc:neo4j:bolt://localhost:port") ;

Upvotes: 0

Views: 104

Answers (1)

Andy Guibert
Andy Guibert

Reputation: 42926

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.

EDIT: 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;
    }
}

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

Upvotes: 0

Related Questions