Neo4j take to much time while preforming fetch operation

MATCH (Member {memberId: 3})<-[:referred_by*1..10]-(downline)
    WHERE EXISTS(downline.level) AND EXISTS(downline.saleVolume)
    WITH downline.level AS level, SUM(downline.saleVolume) AS totalSaleVolume, COUNT(downline) AS numberOfMembers, COLLECT(downline.memberId) AS sortedMembers
    RETURN level, totalSaleVolume, numberOfMembers, sortedMembers
    ORDER BY level
 neo4j_global = require('neo4j-driver')
    driver_global = neo4j_global.driver('neo4j://localhost:7687', neo4j_global.auth.basic('neo4j','admin'), {
    disableLosslessIntegers: true,
    maxConnectionLifetime: 3600000, // 60 min
    maxConnectionPoolSize: 300, // Adjust based on your needs
    connectionAcquisitionTimeout: 3600000, // 60 min
  })

let neo4jQuery = `MATCH (Member {memberId: 3})<-[:referred_by*1..10]-(downline)
    WHERE EXISTS(downline.level) AND EXISTS(downline.saleVolume)
    WITH downline.level AS level, SUM(downline.saleVolume) AS totalSaleVolume, COUNT(downline) AS numberOfMembers, COLLECT(downline.memberId) AS sortedMembers
    RETURN level, totalSaleVolume, numberOfMembers, sortedMembers
    ORDER BY level;`;
    const startTime = Date.now();
    console.log('startTime::::::::::::::',startTime)
    const session = driver_global.session({ database: 'neo4j' });
    const result = await session.run(neo4jQuery,{},{ consumeMode: 'no-result' });
    const endTime = Date.now();
    console.log('endTime:::::',endTime)
    const timeTaken = endTime - startTime;
    console.log('timeTaken:::::::::::::::',timeTaken)
    res.send(result.records.map(record => record.toObject()))

This is query i'm try to execute using nodesJS. and i have used neo4j-driver lib for connectivity of neo4j in my node js project.

Issues:-

  • When i'm trying to fetch data from neo4j it take around 3 to 4 sec to retrieve the data.

  • It's not for only complex query but also for use basic query.

  • I'm taking about when that query is not store into neo4j cache after one hit neo4j has store into their cache then second time i hit query it took 500 ms. but the issue is that why first time it took long time instead of using this query into neo4j browser it took small time as compare to code level.

  • I have updated indexes, optimised all the query , update the neo4j version and node version but still facing same issue.

I'm looking forward to see your response and your's approach.

Thanks

Anant

I don't believe Neo4j Browser reports the entire processing time (only time that the database takes to process), so it leaves out time for routing, sending query, serialize/deserialize data, etc. If you pull the database processing number from the summary object of the driver, is it closer to what you're seeing in browser?

Also, the reason the first run of the query is longer than the first is that the query/path/planner are all cached for awhile, so future runs of the same query are faster. If the database memory doesn't have that cache to use, it has to do all those steps fresh.