Queries Module

const queries = require('@arangodb/aql/queries')

The query module provides the infrastructure for working with currently running AQL queries via arangosh.

Properties

queries.properties() Returns the servers current query tracking configuration; we change the slow query threshold to get better results:

  1. arangosh> var queries = require("@arangodb/aql/queries");
  2. arangosh> queries.properties();
  3. arangosh> queries.properties({slowQueryThreshold: 1});
  4. arangosh> queries.properties({slowStreamingQueryThreshold: 1});

Show execution results

Hide execution results

  1. {
  2. "code" : 200,
  3. "enabled" : true,
  4. "trackSlowQueries" : true,
  5. "trackBindVars" : true,
  6. "maxSlowQueries" : 64,
  7. "slowQueryThreshold" : 10,
  8. "slowStreamingQueryThreshold" : 10,
  9. "maxQueryStringLength" : 4096
  10. }
  11. {
  12. "code" : 200,
  13. "enabled" : true,
  14. "trackSlowQueries" : true,
  15. "trackBindVars" : true,
  16. "maxSlowQueries" : 64,
  17. "slowQueryThreshold" : 1,
  18. "slowStreamingQueryThreshold" : 10,
  19. "maxQueryStringLength" : 4096
  20. }
  21. {
  22. "code" : 200,
  23. "enabled" : true,
  24. "trackSlowQueries" : true,
  25. "trackBindVars" : true,
  26. "maxSlowQueries" : 64,
  27. "slowQueryThreshold" : 1,
  28. "slowStreamingQueryThreshold" : 1,
  29. "maxQueryStringLength" : 4096
  30. }

Currently running queries

We create a task that spawns queries, so we have nice output. Since this task uses resources, you may want to increase period (and not forget to remove it… afterwards):

  1. arangosh> var theQuery = 'FOR sleepLoooong IN 1..5 LET sleepLoooonger = SLEEP(1000) RETURN sleepLoooong';
  2. arangosh> var tasks = require("@arangodb/tasks");
  3. arangosh> tasks.register({
  4. ........> id: "mytask-1",
  5. ........> name: "this is a sample task to spawn a slow aql query",
  6. ........> command: "require('@arangodb').db._query('" + theQuery + "');"
  7. ........> });
  8. arangosh> queries.current();

Show execution results

Hide execution results

  1. {
  2. "id" : "mytask-1",
  3. "name" : "this is a sample task to spawn a slow aql query",
  4. "created" : 1632847867.1329696,
  5. "type" : "timed",
  6. "offset" : 0,
  7. "command" : "(function (params) { require('@arangodb').db._query('FOR sleepLoooong IN 1..5 LET sleepLoooonger = SLEEP(1000) RETURN sleepLoooong'); } )(params);",
  8. "database" : "_system"
  9. }
  10. [
  11. {
  12. "id" : "70064",
  13. "database" : "_system",
  14. "user" : "root",
  15. "query" : "FOR sleepLoooong IN 1..5 LET sleepLoooonger = SLEEP(1000) RETURN sleepLoooong",
  16. "bindVars" : {
  17. },
  18. "started" : "2021-09-28T16:51:07Z",
  19. "runTime" : 1.0265467730005184,
  20. "state" : "executing",
  21. "stream" : false
  22. }
  23. ]

The function returns the currently running AQL queries as an array.

Slow queries

The function returns the last AQL queries that exceeded the slow query threshold as an array:

  1. arangosh> queries.slow();

Show execution results

Hide execution results

  1. [ ]

Clear slow queries

Clear the list of slow AQL queries:

  1. arangosh> queries.clearSlow();
  2. arangosh> queries.slow();

Show execution results

Hide execution results

  1. {
  2. "code" : 200
  3. }
  4. [ ]

Kill

Kill a running AQL query:

  1. arangosh> var runningQueries = queries.current().filter(function(query) {
  2. ........> return query.query === theQuery;
  3. ........> });
  4. arangosh> queries.kill(runningQueries[0].id);

Show execution results

Hide execution results

  1. {
  2. "code" : 200
  3. }