Skip to content

Commit

Permalink
Merge pull request #622 from vitessio/high-prio-admin-execs
Browse files Browse the repository at this point in the history
Run admin benchmark with the highest priority
  • Loading branch information
frouioui authored Nov 14, 2024
2 parents e90c637 + aa18ede commit 458fda6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
3 changes: 3 additions & 0 deletions go/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package api

import (
"log"

"github.com/spf13/cobra"
"github.com/vitessio/arewefastyet/go/server"
)
Expand All @@ -30,6 +32,7 @@ func ApiCmd() *cobra.Command {
Use: "api",
Short: "Starts the api server of arewefastyet and the CRON service",
RunE: func(cmd *cobra.Command, args []string) error {
log.Println("Starting server...")
err := srv.Init()
if err != nil {
return err
Expand Down
35 changes: 31 additions & 4 deletions go/server/cron_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,31 +183,58 @@ func (s *Server) getNumberOfBenchmarksInDB(identifier executionIdentifier) (int,
return nb, nil
}

// cronExecutionQueueWatcher runs an infinite loop that watches the execution queue
// it will send an item to the Executor based on different priority rules ordered that way:
// 0. No executions that are in progress will get executed
// 1. Admin executions always get executed first no matter what
// 2. Execution of the same type (workload/commit) will be executed sequentially
// 3. If none of this priority match, a random element is picked
func (s *Server) cronExecutionQueueWatcher() {
var lastExecutedId executionIdentifier
queueWatch := func() {
mtx.Lock()
defer mtx.Unlock()
if currentCountExec >= maxConcurJob {
if currentCountExec >= maxConcurJob || len(queue) == 0 {
return
}

// Prioritize executing the same configuration of benchmark in a row
// Look for what's in the queue, specifically here is what we look for:
// - An execution that matches the previous execution
// - The first admin execution
var lastBenchmarkIsTheSame bool
var nextExecuteElement *executionQueueElement
var firstAdminExecuteElement *executionQueueElement
for _, element := range queue {
if element.Executing {
continue
}
if element.identifier.equalWithoutUUID(lastExecutedId) {

// Look if there is a matching execution in the queue
if nextExecuteElement == nil && element.identifier.equalWithoutUUID(lastExecutedId) {
nextExecuteElement = element
lastBenchmarkIsTheSame = true
}

// Look if there is any admin execution in the queue
if firstAdminExecuteElement == nil && element.identifier.Source == "admin" {
firstAdminExecuteElement = element
}

// If both the first admin and next execution are not nil, we found what we want, we can stop
if nextExecuteElement != nil && firstAdminExecuteElement != nil {
break
}
}

// If we found an admin execution and the next execution we found is either nil or not an admin
// we force execute the first admin execution we found.
if firstAdminExecuteElement != nil && (nextExecuteElement == nil || nextExecuteElement.identifier.Source != "admin") {
nextExecuteElement = firstAdminExecuteElement
lastBenchmarkIsTheSame = false
}

// If we did not find any matching element just go to the first one which is not executing
if nextExecuteElement == nil {
if firstAdminExecuteElement == nil && nextExecuteElement == nil {
for _, element := range queue {
if !element.Executing {
nextExecuteElement = element
Expand Down

0 comments on commit 458fda6

Please sign in to comment.