Skip to content

[Proposal] Reduce unnecessary DB queries for Actions tasks #24544

Closed
@wolfogre

Description

@wolfogre

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

  1. Fetch tasks with 0 version number when it’s the first time.
  2. Fetch tasks with the responded version number when it didn't get a task last time.
  3. Fetch tasks with 0 version number when it got a task last time.

Here's a simulation:

Gitea   Runner
  ← 0  
13 != 0, query db  → 13, no task  
  ← 13  
13 == 13, skip query  → 13, no task  
  ← 13  
13 != 14, query db  → 14, a task  
  ← 0  
14 != 0, query db  → 14, no task  
  ← 14  
14 == 14, skip query  → 14, no task  

Advantages

  • Easy to implement. No need to modify existing mechanisms.
  • Compatible with other improvement measures.

Metadata

Metadata

Assignees

Labels

topic/gitea-actionsrelated to the actions of Giteatype/proposalThe new feature has not been accepted yet but needs to be discussed first.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions