Query monitoring and termination

Query monitoring and termination can be done manually from the Workbench or by running a JMX operation, and automatically - by configuring GraphDB to abort queries after a certain query-timeout is reached.

Query monitoring and termination using the workbench

When there are running queries their number is shown up next to the Repositories dropdown menu.

To track and interrupt long running queries:

  1. Go to Monitoring -> Queries or click the Running queries status next to the Repositories dropdown menu.
  2. Press the Abort query button to stop a query.

Note

If you are connected to a remote location, you need to have the JMX configured properly. See how in Administration tools.

To pause the current state of the running queries use the Pause button. Note that this will not stop their execution on the server!

_images/query-monitoring.png

To interrupt long running queries, click the Abort query button.

Attribute Description
id the ID of the query
node local or remote worker node repository id
type the operation type QUERY or UPDATE
query the first 500 characters of the query string
lifetime the time in seconds since the iterator was created
state the low level details for the current query collected over the JMX interface

You can also interrupt a query directly from the SPARQL Editor:

_images/editorWithAbort.png

Query monitoring and termination using the JMX interface

Query monitoring

GraphDB offers a number of monitoring and control functions through JMX. It also provides detailed statistics about executing queries or more accurately query result iterators. This is done through the RepositoryMonitor MBean, one for each repository instance. Each bean instance is named after the storage directory of the repository it relates to.

Package com.ontotext
MBean name RepositoryMonitor

The RepositoryMonitor Mbean has two attributes TrackRecords and TrackRecordsNumber.

TrackRecords attribute is an array of objects with the following attributes:

Attribute Description
msSinceCreated the time (in ms) since the iterator was created
numberOfOperations the total number of operations for this iterator
requestedToStop indicates if the query has been requested to terminate early (see below)
sparqlString the full text of the query
state the current state of the iterator: ACTIVE, IN_HAS_NEXT , COMMIT_PENDING , IN_COMMIT , IN_COMMIT_PLUGIN , IN_NEXT , BEGIN_PENDING , IN_PARALLEL_IMPORT , IN_PARALLEL_COMMIT , ENQUEUED, CLOSED
trackAlias an unique alias for this iterator given by the client
trackId a unique ID for this iterator - if debug level is used to increase the detail of the GraphDB output, then this value is used to identify queries when logging the query execution plan and optimisation information.
type the type of this iterator - UPDATE or READ

TrackRecordsNumber` attributes is the number of running queries.

_images/query_load.png

The collection of these objects grows for each executing/executed query, however, older objects in the CLOSED state expire and are removed from the collection as the query result iterators are garbage collected.

Terminating a query

Following operations are available with RepositoryMonitor MBean:

Operation Description
requestStop Request that a query terminates early; parameter: trackId of the query to stop.
requestStopByAlias Request that a query terminates early; parameter: trackAlias of the query to stop.
getFullSparqlString Returns the full text of the query; parameter: trackId of the query.

requestStop and requestStopByAlias operations allow an administrator to request earliest as possible termination of a query.

To terminate a query, execute the requestStop command with given trackId of the query; or requestStopByAlias with given trackAlias.

As a result:

  • The requestedToStop attribute is set to true.
  • The query terminates normally when hasNext() returns false.
  • Collected result so far will be returned by the interrupted query.

Terminating a transaction

It is also possible to terminate a long committing update transaction. For example, when committing a ‘chain’ of many thousands of statements using some transitive property, the inferencer will attempt to materialise all possible combinations leading to hundreds of millions of inferred statements. In such a situation, you can abort the commit operation and rollback to the state the database had before the commit was attempted.

The following MBean is used:

Package com.ontotext
MBean name OwlimRepositoryManager

This MBean has no attributes:

Operation Description
abortTransactionCommit Request that the currently executing (lengthy) commit operation be terminated and rolled back.

Automatically prevent long running queries

You can set a global query time-out period by adding a configuration parameter query-timeout. All queries will stop after this many seconds, where a default value of 0 indicates no limit.