4

We are trying to access Neo4J graph database server from multiple nodejs processes. Each process is creating their own connections and trying to connect/write to neo4j database. We tried with around ~10 processes and it didn't able to handle these many connections.

Given that, all connections are with high workload.

Can anybody suggest how many prallel connections to use for Neo4J DB is practical and how to scale to support more connections?

Edit: More Info connections are created using 'neo4j' npm package as below:

var neo4j = require('neo4j')
var config = require('./config')
var graph = new neo4j.GraphDatabase(config.db.neo4j)

//usage
graph.query(query, params, function(err, result){
   //
}) 

I am assuming for each process, this code is creating new connection(each instance of 'graph' variable), as there doesn't seems to be any pooling mechanism apparently.

I am assuming the number of connection based on the nodejs processes spawned(all processes are single threaded).

Rana
  • 5,912
  • 12
  • 58
  • 91
  • How long is a piece of string? – Dave Bennett May 21 '15 at 02:04
  • Sorry, no idea what you meant. Can you plz elaborate in details what you wanted to know? – Rana May 21 '15 at 02:35
  • 2
    Rana, please provide details on what kind of connections they're making, and what symptom you're seeing that has you saying "wasn't able to handle this many connections". How did you measure that it's 10? You've provided very little to go on here, this really can't be answered until you can provide more. – FrobberOfBits May 21 '15 at 03:08
  • What exactly error message are you seeing? – Stefan Armbruster May 21 '15 at 07:14
  • Your code still isn't specifying how you're connecting. require('redis') suggests you're using redis and not neo4j, that's a different database. – FrobberOfBits May 21 '15 at 10:21
  • Oops, sorry. I was mixing this thread with another problem I had and thus added the edited part wrong. I have now corrected it. Hope now it make better sense. – Rana May 21 '15 at 14:34

2 Answers2

1

Not sure if this helps you but if you want to perform concurrent read/writes, as such there is no limit on that. But, the main question thing that you need to consider is the operation you want to perform. If you are performing simple read/writes which are not costly, then you can get away with more concurrent requests compared to when you want to perform heavier operations.

For instance, There were 5-6 graph queries that I was trying to run in parallel some time back and I actually crashed the server. On the other hand, some of the scripts that I now use run close to 50-100 queries in parallel and there is no issue.

Himanshu Jain
  • 1,809
  • 1
  • 13
  • 23
0

I have the same problem. Try use the @qualitech/Qneo4j npm package to connect.

Try change the parameters autoclosedriver with false.

const QNeo4j = require('@qualitech/qneo4j')

// simplest
const db = new QNeo4j({
    url: 'bolt://localhost:7687'
})

// full options
const db = new QNeo4j({
    url: 'bolt://localhost:7687',
    username: 'neo4j',       // default: 'neo4j'
    password: 'admin',       // default: 'admin'

    // description: if true, returns raw value of the Neo4j.
    raw: false,              // default: false,

    // description: closes the Neo4j driver after the execute method or transaction.
    autoCloseDriver: true,   // default: true

    // description: expects to receive a callback function. This callback is called every time an error occurs within the QNeo4j module.
    notifyError: (error, query) => console.log(error, query),

    // description: all configuration available to the driver Neo4j can be set here. See more https://neo4j.com/docs/driver-manual/current/client-applications/
    driverConfig: {
        // ... neo4j driver configuration
    }
})

In the driverConfig use examples

{
  maxConnectionLifetime: 3 * 60 * 60 * 1000, // 3 hours
  maxConnectionPoolSize: 50,
  connectionAcquisitionTimeout: 2 * 60 * 1000 // 120 seconds
  connectionTimeout: 
  maxTransactionRetryTime: 
}

ALL options in https://neo4j.com/docs/driver-manual/current/client-applications/

RobC
  • 22,977
  • 20
  • 73
  • 80
Skyrioca
  • 31
  • 2