From aa18edeb81de3a11172ed64d0f4074debae7428c Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Thu, 14 Nov 2024 12:07:49 -0600 Subject: [PATCH] Run admin benchmark with the highest priority Signed-off-by: Florent Poinsard --- go/cmd/api/api.go | 3 +++ go/server/cron_execution.go | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/go/cmd/api/api.go b/go/cmd/api/api.go index ecf656a41..18bad14d8 100644 --- a/go/cmd/api/api.go +++ b/go/cmd/api/api.go @@ -19,6 +19,8 @@ package api import ( + "log" + "github.com/spf13/cobra" "github.com/vitessio/arewefastyet/go/server" ) @@ -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 diff --git a/go/server/cron_execution.go b/go/server/cron_execution.go index 13ca926ef..c3096a87a 100644 --- a/go/server/cron_execution.go +++ b/go/server/cron_execution.go @@ -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