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

Run admin benchmark with the highest priority #622

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...")
Copy link
Member Author

Choose a reason for hiding this comment

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

Intended change FYI.

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
Loading