Reputation: 6154
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).
Upvotes: 4
Views: 3632
Reputation: 31
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/
Upvotes: 0
Reputation: 1818
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.
Upvotes: 1