Killing a Long-running Query
source link: http://jsteemann.github.io/blog/2016/01/26/killing-a-long-running-query/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Killing a Long-running Query
Jan 26th, 2016
Suppose there is an AQL query that’s executing in the server for a long time already and you want to get rid of it. What can be done to abort that query?
If a connection to the server can still be established, the easiest is to use the ArangoShell to fetch the list of currently executing AQL queries and send a kill command to the server for the correct query.
To start, we can fetch the list of all running queries and print their ids, query strings and runtimes. This is only inspection and does not abort any query:
printing all currently running queries
|
Here’s an example result for the list of running queries:
example list of currently running queries
|
To now kill a query from the list, we can pass the query’s id to kill:
killing a specific query
|
If a query was actually killed on the server, that call should return without an error, and the server should have logged a warning in addition.
If we wanted to abort one or many queries from the list solely by looking at query string patterns or query runtime, we could iterate over the list of current queries and kill each one that matches a predicate.
For example, the following snippet will abort all currently running
queries that contain the string SLEEP
anywhere inside their query string:
aborting all queries containing the word SLEEP inside the query string
|
Filtering based on current query runtime is also simple, by adjusting the predicate. To abort all queries that ran longer than 30 seconds use:
aborting all queries running at least 30 seconds
|
Please make sure the predicates are correct so only the actually intended queries get aborted!
To test a predicate without killing a query, use the above code without the
forEach
part that did the killing.
Posted by jsteemann
Jan 26th, 2016AQL, ArangoDB, ArangoShell
« Small things in 2.8: explain improvements Compiling V8 with g++6 »
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK