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

Adding support for task priority #181

Open
FreCap opened this issue Feb 18, 2021 · 4 comments
Open

Adding support for task priority #181

FreCap opened this issue Feb 18, 2021 · 4 comments

Comments

@FreCap
Copy link

FreCap commented Feb 18, 2021

Currently all tasks have a FIFO policy (or whether time they are scheduled).

In a number of use cases, where queue is larger than the processing power, we might want to pull higher priority tasks first (at cost of starvation of lower priority ones).

This would not be a breaking change, since by default all tasks would have same priority and hence the ones with the lowest executionTime would always be run first.

Can this feature be of any interest to the broader community?

@kagkarlsson
Copy link
Owner

For high-throughput use-cases I can see this could be useful. For example avoiding that a high number of one-time tasks prevent recurring tasks from running. Recurring tasks would probably have a higher priority by default.

Currently I think a workaround would be to run multiple Scheduler instances, backed by different tables.

@FreCap
Copy link
Author

FreCap commented Feb 19, 2021

This can be helpful also in low throughput, long queues situations.

Ideally we could have something that is not a workaround, since the queues could possibly be many, and then we have to deal with which threads have to get priority over others.

To achieve this we should expose a method like runAnyDueExecutions with a few changes: we should loop getDue and PickAndExecute until we reach pollingLimit (or another variable like nTaskRunLimit)
image
This is a method that in any case I would love to expose in the scheduler (runDueExecutions(int nTaskRunLimit)), please let me knwo if it is ok.

@kagkarlsson do you think the priority queue change could be merged back in? Are there specific design considerations you would like to take into account?

@kagkarlsson
Copy link
Owner

For adding support for task-priority to the scheduler, wouldn't the best solution be to add the priority field to the database table, and have the query for getDue fetch executions order by priority desc, execution_time asc ? (though this will be a bit tricky index well I think)

This is a method that in any case I would love to expose in the scheduler (runDueExecutions(int nTaskRunLimit)), please let me knwo if it is ok.

What would such a method do? Are you looking to trigger check for due executions ad-hoc, i.e. outside the normal polling-interval?

@FreCap
Copy link
Author

FreCap commented Feb 19, 2021

For adding support for task-priority to the scheduler, wouldn't the best solution be to add the priority field to the database table, and have the query for getDue fetch executions order by priority desc, execution_time asc ? (though this will be a bit tricky index well I think)

Perfect

Yes, runDueExecutions(Instant now, int nTaskRunLimit) would be an ad hoc trigger. RunForeverExecutor can have limitations in terms of lifecycle,
e.g. If if you have multiple types of tasks (with different dataClass) and we want to run all tasks of dataClass A before running the ones of dataClass B, we cannot achieve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants