Mykola Makhynko
Mykola Makhynko

Reputation: 113

Query timeout in Neo4j 3.0.6

It looks like previously working approach is deprecated now:

unsupported.dbms.executiontime_limit.enabled=true
unsupported.dbms.executiontime_limit.time=1s

According to the documentation new variables are responsible for timeouts handling:

dbms.transaction.timeout
dbms.transaction_timeout

At the same time the new variables look related to the transactions.

The new timeout variables look not working. They were set in the neo4j.conf as follows:

dbms.transaction_timeout=5s
dbms.transaction.timeout=5s

Slow cypher query isn't terminated.

Then the Neo4j plugin was added to model a slow query with transaction:

    @Procedure("test.slowQuery")
    public Stream<Res> slowQuery(@Name("delay") Number Delay )
    {
        ArrayList<Res> res = new ArrayList<>();

        try ( Transaction tx = db.beginTx() ){
            Thread.sleep(Delay.intValue(), 0);
            tx.success();
        } catch (Exception e) {
            System.out.println(e);
        }

        return res.stream();
    }

The function served by the plugin is executed with neoism Golang package. And the timeout isn't triggered as well.

Upvotes: 0

Views: 1349

Answers (2)

Mykola Makhynko
Mykola Makhynko

Reputation: 113

According to the documentation the transaction guard is interested in orphaned transactions only.

The server guards against orphaned transactions by using a timeout. If there are no requests for a given transaction within the timeout period, the server will roll it back. You can configure the timeout in the server configuration, by setting dbms.transaction_timeout to the number of seconds before timeout. The default timeout is 60 seconds.

I've not found a way how to trigger timeout for a query which isn't orphaned with a native functionality.

@StefanArmbruster pointed a good direction. The timeout triggering functionality can be got with creating a wrapper function in Neo4j plugin like it is made in apoc.

Upvotes: 0

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

The timeout is only honored if your procedure code invokes either operations on the graph like reading nodes and rels or explicitly checks if the current transaction is marked as terminate.

For the later, see https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/master/src/main/java/apoc/util/Utils.java#L41-L51 as example.

Upvotes: 0

Related Questions