Running an excessive amount queries simultaneously may lead to degraded Looker instance performance, especially queries run by an API user to send out bulk schedules or queries requiring post-processing features (such as merged results, custom fields, and table calculations). In these situations, the fastest way to bring an instance back to a normal stage is to kill all running queries to help with restoring CPU and memory.
I am sharing an example script to kill running queries using Looker Python SDK (either all running queries, or selective queries with two optional arguments: 'user_id' and 'source')
Link to Google Colab to run as an one-off task.
sdk = looker_sdk.init40()
def kill_queries(user_id=None, source=None):
"""Kill running queries in an instance.
user_id(int): id of the user whose queries are to be killed
source(str): common values are 'merge_query', 'explore', 'dashboard', 'look', 'regenerator'
queries = sdk.all_running_queries()
if len(queries) == 0:
print('Currently, there is no running query in the instance')
for i in range(0, len(queries)):
if queries[i]['source'] == source or queries[i]['user']['id'] == user_id:
print('Killed query task id' + queries[i]['query_task_id'])
print('Currently, there are no running queries that meet the conditions')