[Proposal] Reduce unnecessary DB queries for Actions tasks #24544
Labels
topic/gitea-actions
related to the actions of Gitea
type/proposal
The new feature has not been accepted yet but needs to be discussed first.
Uh oh!
There was an error while loading. Please reload this page.
This looks familiar with #24543, but it's quite different.
Background
Gitea will start a transaction to find and assign a task to the runner when it requests a new one. However, we know that there may not be a task available most of the time, so Gitea has to roll back the transaction and respond with "no task yet, try again later."
Starting a transaction is an expensive operation. However, we don't have to do it every time.
Solution
Record a version number for table of Actions jobs
PS: You might wonder why it's not "table of Actions tasks". Never mind, just a few implementation details.
Increase the version number once the data table changes. The number can be stored in DB and cached in memory.
When Gitea receives a request for a task, it compares the version number in the request with the current version number. If they are equal, it responds with "no task available yet".
Otherwise, start a transaction to query and assign a task.
Gitea responds with the current version number regardless of whether there is a task available.
Runners fetch tasks with the version number
0
version number when it’s the first time.0
version number when it got a task last time.Here's a simulation:
Advantages
The text was updated successfully, but these errors were encountered: