Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show queue position while waiting for query to execute #3583

Closed
wants to merge 1 commit into from

Conversation

washort
Copy link

@washort washort commented Mar 13, 2019

This puts the number of queries currently waiting to be executed in the status for a job reported in the query execution page.

@ghost ghost assigned washort Mar 13, 2019
@ghost ghost added the in progress label Mar 13, 2019
client/app/pages/queries/query.html Outdated Show resolved Hide resolved
redash/tasks/queries.py Outdated Show resolved Hide resolved
Copy link
Member

@arikfr arikfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments. I suggest you get familiar with how Celery handles the queue before implementing this. I doubt it's possible to reliably tell how many tasks await ahead of a given task in an environment where there are multiple workers processing the queue (because you don't know which one will get it).

Also once you try poking Celery to get to know how many queries are currently reserved, you will realize it's not feasible for a request that comes in every second (in terms of how long it takes all the workers to reply).

@@ -71,12 +72,21 @@ def to_dict(self):
else:
query_result_id = None

queriesAhead = 0
if task_status == 'PENDING':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will get PENDING for non existing task id as well. In which case, it won't be found in the queue and you will report there are no queries ahead of it.

Query can be reserved by a worker (which I guess is also reported as PENDING), and then it won't be in get_waiting_in_queue list.

redash/tasks/queries.py Outdated Show resolved Hide resolved
redash/tasks/queries.py Outdated Show resolved Hide resolved
@rafrombrc
Copy link

@arikfr Maybe it would help if we stepped back to explain what we're trying to accomplish here. It's not necessarily important that we have an exactly correct count of how many queries are in front of the current one in the queue. What is important is that folks get an idea about the relative state of things. Is everything flowing smoothly and the queues are relatively empty, or are the queues relatively gummed up so the user can expect that the user should expect much higher latency than usual.

Currently users click "execute" and experience wait times ranging from a few seconds to 5-10 minutes for the same query, depending on the overall load on the entire queue / data source system. We're hoping to make it so that, when wait times are long due to heavy load, the user at least gets an indication this is so.

Given this requirement, how would you suggest we tackle the problem?

@arikfr
Copy link
Member

arikfr commented Mar 13, 2019

Maybe it would help if we stepped back to explain what we're trying to accomplish here.

Good idea! :-)

What is important is that folks get an idea about the relative state of things. Is everything flowing smoothly and the queues are relatively empty, or are the queues relatively gummed up so the user can expect that the user should expect much higher latency than usual.

Based on this description, I would suggest a different solution. We recently added new screens for admins to see Celery status (#3057). Using the same raw data, we can create a less technical view for end users that will reflect the queues status.

There is the question of what to show exactly, where to show it and then how to implement (for example, I would go for a separate API call that is no combined with job status polling). Can you open a new issue so we can discuss this?

@washort washort force-pushed the execute-queue-status branch from c1ca6e0 to fa7f86b Compare March 18, 2019 19:07
@washort
Copy link
Author

washort commented Mar 18, 2019

I've moved the queue status check into a separate request and made it check the data source for the right queue to query. It checks the status every 10 seconds that it's in "waiting" state.

example

@@ -207,7 +207,7 @@ <h3>
<rd-timer timestamp="queryResult.getUpdatedAt()"></rd-timer>
</div>
<div class="alert alert-info m-t-15" ng-show="queryResult.getStatus() == 'waiting'">
Query in queue&hellip;
Query in queue <span ng-if="queryResult && queryResult.queueStatus">(waiting on {{queryResult.queueStatus}} <ng-pluralize count=queryResult.queueStatus when="{'0': 'queries', 'one': 'query', 'other': 'queries'}"></ng-pluralize>)</span>&hellip;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 case could be omitted (other covers it)

if (this.getStatus() === 'waiting') {
const p = $http.get(`/api/queue_status/${this.job.id}?data_source=${dataSourceId}`);
p.then((response) => {
$timeout(() => this.refreshQueueStatus(dataSourceId), 10000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When query page is left, does this interval halt?

@jezdez jezdez mentioned this pull request Mar 26, 2019
6 tasks
@arikfr arikfr closed this Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants