cancel
Showing results for 
Search instead for 
Did you mean: 

Neo4j connections are growing and reach connection timeout

Hi. I'm working on a project which is using Neo4j Enterprise v. 4.2 .
I've stumbled upon problem, where under load connections number start to bloat, even if there is no need. They reach up to 100 connections and higher in the dbms connection list, while load remains approximately 2-4 requests per second. It looks like connections are either not being released, or are not reused.
In the application everything is built on the top of OGM v.3.2.15 with direct session management. Typical code is the next:

INITIALIZATION:

BoltDriver boltDriver =
        new BoltDriver(neo4jDriver) {
          @Override
          public synchronized void close() {
          }
        };
boltDriver.configure(new Builder().database("dbName").build());
SessionFactory sessionFactory = new SessionFactory(ogmDriver);

CALLING:

    Transaction tx = null;
    try {
      Session session = sessionFactory.openSession();
      tx = session.beginTransaction(txType);
      Iterable<C> result = session.query(clazz, cypher, parameters);

      tx.commit();

      return result;
    } catch (Exception e) {
      if (tx != null) tx.rollback();
      throw e;
    }

Similar procedure is used for most of the cases.

Recently I have added new operations based on pure Neo4j Driver v.4.0.0.1 with the next way of code running:
INITIALIZATION:

Config config = Config.builder()
        .withMaxTransactionRetryTime(5, TimeUnit.SECONDS)
        .build();

Driver  driver = GraphDatabase.driver(neo4jUri, *some authorization*, config);

SessionConfig sc = SessionConfig.builder()
        .withDefaultAccessMode(AccessMode.WRITE)
        .withDatabase("dbName")
        .build();

CALLING:

public List<Record> runQuery(ParamQuery query) {
    try (Session session = driver.session(sc)) {
      return session.run(query.getCypher(), query.getParams()).list();
    }
  }

In some circumstances, usually after load on the OGM-based code, my pure Neo4j-based code freezes on transaction start and throws an error after a minute:

ServiceUnavailableException: Unable to connect to x.x.x.x(x.x.x.x):7687, ensure the database is running and that there is a working network connection to it.

Need your help in ideas what could it be and how to solve it. I'm currently out of ideas how to manage it.

0 REPLIES 0