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

  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. }

Hide execution results

Currently running queries

We create a task that spawns queries, so we have nice output. Since this taskuses 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

  1. {
  2. "id" : "mytask-1",
  3. "name" : "this is a sample task to spawn a slow aql query",
  4. "created" : 1568175891.5106137,
  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" : "443",
  13. "query" : "FOR sleepLoooong IN 1..5 LET sleepLoooonger = SLEEP(1000) RETURN sleepLoooong",
  14. "bindVars" : {
  15. },
  16. "started" : "2019-09-11T04:24:51Z",
  17. "runTime" : 1.0511929988861084,
  18. "state" : "executing",
  19. "stream" : false
  20. }
  21. ]

Hide execution results

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

  1. [ ]

Hide execution results

Clear slow queries

Clear the list of slow AQL queries:

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

Show execution results

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

Hide execution results

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

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

Hide execution results