neo4j / neo4j-javascript-driver

Neo4j Bolt driver for JavaScript

Home Page:https://neo4j.com/docs/javascript-manual/current/

Repository from Github https://github.comneo4j/neo4j-javascript-driverRepository from Github https://github.comneo4j/neo4j-javascript-driver

Same query hitting same db - response time much slower via driver vs neo4j browser?

xharmagne opened this issue · comments

Hello, newbie here, not sure if this is a bug or expected (for some reason I'm not aware of) or if there's something I can do to speed this up -

When I run the exact same query against the same db, via neo4j browser it takes 2ms. Via neo4j driver session.run it takes 800~ms.

Any thoughts on this? Any kind of help would be appreciated :)

Neo4j Version: 4 on AuraDB free
Neo4j Mode: Single instance
Driver version: JavaScript driver 4.4.0
Operating System: macOS 11.6

image

Repro steps

  1. 1 Neo4j db on AuraDB free
  2. Run a query via neo4j browser - it takes 2ms
    image
  3. Run same query via JS driver - query summary says consumed after 1 and available after 3, but timing says 800~ms
const driver = neo4j.driver(...);
const session = driver.session({ defaultAccessMode: neo4j.session.READ });
...
const tbefore = Date.now();
const results = await session.run(
  `MATCH (m:Move) where m.id = '${id}'
	  OPTIONAL MATCH (m)<-[:SHOWS]-(i:Image) 
	  WITH m, HEAD(COLLECT(i)) as firstImage 
	  RETURN m as move, firstImage as image`
  );
const tafter = Date.now();
console.log("GET MOVE: Ran query:", tafter - tbefore);
...
// process records
await session.close();
await driver.close();

Logs:
GET MOVE: Ran query: 868

Summary from results.summary:

 {
  query: {
    text: "MATCH (m:Move) where m.id = 'e3568424-b963-4982-96ea-d33f6df97491'\n" +
      '\t\t OPTIONAL MATCH (m)<-[:SHOWS]-(i:Image) \n' +
      '\t\t WITH m, HEAD(COLLECT(i)) as firstImage \n' +
      '\t\t RETURN m as move, firstImage as image',
    parameters: {}
  },
  queryType: 'r',
  counters: QueryStatistics {
    _stats: {
      nodesCreated: 0,
      nodesDeleted: 0,
      relationshipsCreated: 0,
      relationshipsDeleted: 0,
      propertiesSet: 0,
      labelsAdded: 0,
      labelsRemoved: 0,
      indexesAdded: 0,
      indexesRemoved: 0,
      constraintsAdded: 0,
      constraintsRemoved: 0
    },
    _systemUpdates: 0
  },
  updateStatistics: QueryStatistics {
    _stats: {
      nodesCreated: 0,
      nodesDeleted: 0,
      relationshipsCreated: 0,
      relationshipsDeleted: 0,
      propertiesSet: 0,
      labelsAdded: 0,
      labelsRemoved: 0,
      indexesAdded: 0,
      indexesRemoved: 0,
      constraintsAdded: 0,
      constraintsRemoved: 0
    },
    _systemUpdates: 0
  },
  plan: false,
  profile: false,
  notifications: [],
  server: ServerInfo {
    address: '.....databases.neo4j.io:7687',
    version: 'Neo4j/4.3-aura',
    agent: 'Neo4j/4.3-aura',
    protocolVersion: 4.3
  },
  resultConsumedAfter: Integer { low: 2, high: 0 },
  resultAvailableAfter: Integer { low: 4, high: 0 },
  database: { name: 'neo4j' }
}

Hi @xharmagne,

are you running your JS code snippet in which environment (nodejs, chrome, firefox..) ? If you are running in firefox/chrome or other browser, I recommend you update the driver version 4.4.1 since some serialisation issues in web browsers were solved in this patch, see changelog.

I suggest you use console.time/console.timeEnd for measuring it is taking for run. For instance,

console.time('thenameofyourtime')
 
// Your code    
    
console.timeEnd('thenameofyourtime')

Also worth noting that the Browser uses the javascript driver to connect.

Closed due long inactive. This issue could be re-opened if needed.

I am also facing this, using neo4j-driver v5.7.0. the issue is time consumed in neo4j browser for a query is ~20ms, while using the driver facing a huge increase in time ~370ms.

used the console.time and console.timeEnd to still the same time.
environment is nodejs:v18.

     console.time('test1');
      const result = await session.executeRead((tx) => tx.run(query, variables));

      console.timeEnd('test1');

I'm getting the same issue still, in the auradb browser the query takes 29 ms but in my docker container running node 18 it takes around 5 seconds. It also takes around 5.5 seconds to establish an initial driver connection.
image
image
In the above "run" is the neo4j query console.time
and this is in the auradb browser. I only have 2 nodes so querying them shouldn't realistically take this long, and I would imagine that this is an issue either with the neo4j driver js package or auradb.
image
I will also note that the time varies, sometimes the docker one takes like 80-120 ms and sometimes it takes 5+ seconds.

Do ya'll potentially have source maps enabled on node when running your queries?

This is what I was able to narrow it down to for me.

#1168