feat: adding SHUFFLE_SWARM_CONTROL_MODE
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -26,9 +27,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
"sync"
|
"sync"
|
||||||
"math"
|
"time"
|
||||||
|
|
||||||
//"os/signal"
|
//"os/signal"
|
||||||
//"syscall"
|
//"syscall"
|
||||||
@@ -1041,12 +1041,10 @@ func getOrborusStats(ctx context.Context) shuffle.OrborusStats {
|
|||||||
return newStats
|
return newStats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if swarmConfig == "run" || swarmConfig == "swarm" {
|
if swarmConfig == "run" || swarmConfig == "swarm" {
|
||||||
newStats.Swarm = true
|
newStats.Swarm = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Run this 1/10 times
|
// Run this 1/10 times
|
||||||
//if rand.Intn(10) != 1 {
|
//if rand.Intn(10) != 1 {
|
||||||
// return newStats
|
// return newStats
|
||||||
@@ -1077,7 +1075,6 @@ func getOrborusStats(ctx context.Context) shuffle.OrborusStats {
|
|||||||
newStats.MaxMemory = int(pers.MemTotal)
|
newStats.MaxMemory = int(pers.MemTotal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get list of all running containers
|
// Get list of all running containers
|
||||||
containers, err := dockercli.ContainerList(ctx, types.ContainerListOptions{})
|
containers, err := dockercli.ContainerList(ctx, types.ContainerListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1145,7 +1142,7 @@ func getOrborusStats(ctx context.Context) shuffle.OrborusStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newStats.CPUPercent = totalCPU/float64(newStats.CPU)
|
newStats.CPUPercent = totalCPU / float64(newStats.CPU)
|
||||||
newStats.MemoryPercent = memUsage
|
newStats.MemoryPercent = memUsage
|
||||||
|
|
||||||
//log.Printf("[DEBUG] CPU: %.2f, Memory: %.2f", newStats.CPUPercent, newStats.MemoryPercent)
|
//log.Printf("[DEBUG] CPU: %.2f, Memory: %.2f", newStats.CPUPercent, newStats.MemoryPercent)
|
||||||
@@ -1409,6 +1406,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
swarmPollingTime := time.Now()
|
||||||
|
swarmRequestsMade := 0
|
||||||
|
swarmControlMode := false
|
||||||
|
if os.Getenv("SHUFFLE_SWARM_CONTROL_MODE") == "true" {
|
||||||
|
swarmControlMode = true
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("[INFO] Waiting for executions at %s with Environment %#v", fullUrl, environment)
|
log.Printf("[INFO] Waiting for executions at %s with Environment %#v", fullUrl, environment)
|
||||||
hasStarted := false
|
hasStarted := false
|
||||||
for {
|
for {
|
||||||
@@ -1529,6 +1533,20 @@ func main() {
|
|||||||
log.Printf("[WARNING] Throttle - Cutting down requests from %d to %d (MAX: %d, CUR: %d)", len(executionRequests.Data), allowed, maxConcurrency, executionCount)
|
log.Printf("[WARNING] Throttle - Cutting down requests from %d to %d (MAX: %d, CUR: %d)", len(executionRequests.Data), allowed, maxConcurrency, executionCount)
|
||||||
executionRequests.Data = executionRequests.Data[0:allowed]
|
executionRequests.Data = executionRequests.Data[0:allowed]
|
||||||
}
|
}
|
||||||
|
} else if (swarmControlMode && (swarmConfig == "run" || swarmConfig == "swarm")) {
|
||||||
|
if len(executionRequests.Data) > 50 {
|
||||||
|
executionRequests.Data = executionRequests.Data[0:50]
|
||||||
|
}
|
||||||
|
|
||||||
|
if swarmRequestsMade > 100 && time.Since(swarmPollingTime).Seconds() > 5 {
|
||||||
|
log.Printf("[DEBUG] Swarm requests made: %d", swarmRequestsMade)
|
||||||
|
time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||||
|
|
||||||
|
swarmPollingTime = time.Now()
|
||||||
|
swarmRequestsMade = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
swarmRequestsMade += len(executionRequests.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New, abortable version. Should check executionid and remove everything else
|
// New, abortable version. Should check executionid and remove everything else
|
||||||
@@ -1611,7 +1629,6 @@ func main() {
|
|||||||
env = append(env, fmt.Sprintf("SHUFFLE_VOLUME_BINDS=%s", os.Getenv("SHUFFLE_VOLUME_BINDS")))
|
env = append(env, fmt.Sprintf("SHUFFLE_VOLUME_BINDS=%s", os.Getenv("SHUFFLE_VOLUME_BINDS")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if len(os.Getenv("SHUFFLE_APP_SDK_TIMEOUT")) > 0 {
|
if len(os.Getenv("SHUFFLE_APP_SDK_TIMEOUT")) > 0 {
|
||||||
env = append(env, fmt.Sprintf("SHUFFLE_APP_SDK_TIMEOUT=%s", os.Getenv("SHUFFLE_APP_SDK_TIMEOUT")))
|
env = append(env, fmt.Sprintf("SHUFFLE_APP_SDK_TIMEOUT=%s", os.Getenv("SHUFFLE_APP_SDK_TIMEOUT")))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user