Can slow queries be interrupted in DGraph?

Can slow queries be interrupted in DGraph?

Interrupted do you mean canceled?
Dgraph has an option to timeout queries, mutations, and other operations as part of the method. Each client should cover this.


Ratel has the timeout config in the “Extra Settings” in the Connection modal. The default is 20 seconds. Any query beyond 20 seconds is dropped.

Many times timeouts are not valid。I set the timeout time, but at that time, the query is still running。
I wonder if we can stop a query like we can stop a mutation transaction。

You can cancel the gRPC context for the query to stop it.

Is it possible to abort the query using abort transactions

        ts1 := worker.State.GetTimestamp(true)
	_, ts, err := queryWithTs(q1, "application/dql", "", ts1)
	url := fmt.Sprintf("%s/commit?startTs=%d&abort=true", "http://"+testutil.SockAddrHttp, ts1)

Txn aborts are used to cancel a transaction. It does not cancel it mid-processing. e.g., if a query takes 200 ms to process then it wouldn’t get interrupted by calling a txn abort. To do that, cancel the context that’s passed to the query: context - The Go Programming Language

I’ve looking around clients document but only found timeout setting on python, that mean only python support timeout ?

I’m not sure why dgraph-js hasn’t it, but dgraph-js-http has it is “setQueryTimeout”.

see dgraph-js/client.d.ts at master · dgraph-io/dgraph-js · GitHub
and dgraph-js-http/client.d.ts at master · dgraph-io/dgraph-js-http · GitHub

1 Like