Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add graph queries timeout #215

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

feat: add graph queries timeout #215

wants to merge 3 commits into from

Conversation

tipogi
Copy link
Collaborator

@tipogi tipogi commented Nov 21, 2024

Pre-submission Checklist

For tests to work you need a working neo4j and redis instance with the example dataset in docker/db-graph

  • Testing: Implement and pass new tests for the new features/fixes, cargo test.
  • Performance: Ensure new code has relevant performance benchmarks, cargo bench

@tipogi
Copy link
Collaborator Author

tipogi commented Nov 21, 2024

There are two ways to apply a timeout to queries in Neo4j:

Global timeout

To set a global timeout for all transactions, modify the neo4j.conf configuration file. In that branch, the file path would be docker/.database/neo4j/conf/neo4j.conf:

db.transaction.timeout=1s

Verifying the Configuration

To verify if the global timeout configuration was successfully applied (after restarting the container), execute the following Cypher command:

CALL dbms.listConfig() YIELD name, value
WHERE name = 'db.transaction.timeout'
RETURN name, value;

Testing the Global Timeout

Run a query that exceeds the specified timeout, such as:

UNWIND range(1, 1000000000) AS i
RETURN i;

If the timeout is configured correctly, you should receive an error indicating that the query has timed out

global_timeout

Per query timeout

For more customized query timeouts, the APOC plugin is required. Follow these steps

Configuring the APOC Plugin

  1. Download the APOC plugin from the releases page.
  2. Move the downloaded .jar file to the plugins directory in our Neo4j setup, docker/.database/neo4j/plugins
  3. Add Apoc configuration in docker-compose.yml
NEO4JLABS_PLUGINS: '["apoc"]'
NEO4J_dbms_security_procedures_unrestricted: 'apoc.*'
NEO4J_dbms_security_procedures_allowlist: 'apoc.*'

Restarting the Neo4j Container

  1. Remove the data folder from the Neo4j directory (docker/.database/neo4j/data) to reset the database.
  2. Restart the container to apply the changes

Using Per Query Timeout

Once the plugin is installed and the container is restarted, you can apply a timeout to specific queries using apoc.cypher.runTimeboxed

CALL apoc.cypher.runTimeboxed("MATCH (u1:User)-[f:FOLLOWS]-(u2:User)
 RETURN u1, f, u2",
 {}, 20)

If any query exceeding this limit will terminate with an error

apoc_timeout

@SHAcollision
Copy link
Collaborator

There are two ways to apply a timeout to queries in Neo4j:

Really excellent research and summary. Thank you for taking the time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: add timeout to graph queries
2 participants