Reduced execution bytesize

This commit is contained in:
frikky
2021-01-17 15:38:58 +01:00
parent 3b6501c56c
commit 38b454bc38
8 changed files with 94 additions and 16 deletions
@@ -0,0 +1,9 @@
GOOS=linux go build main.go
zip function.zip main
aws lambda update-function-code \
--function-name shuffler-forwarder \
--runtime go1.* \
--zip-file fileb://function.zip \
--handler main \
--role arn:aws:iam::123456789012:role/execution_role
+39
View File
@@ -25,6 +25,8 @@ import (
"github.com/satori/go.uuid"
//network "github.com/docker/docker/api/types/network"
//natting "github.com/docker/go-connections/nat"
"github.com/mackerelio/go-osstat/cpu"
"github.com/mackerelio/go-osstat/memory"
)
// Starts jobs in bulk, so this could be increased
@@ -297,6 +299,41 @@ func initializeImages() {
}
}
// Will be used for checking if there's enough to deploy based on a threshold
// E.g. having maximum CPU and maxmimum RAM
// Does this work containerized?
func getStats() {
fmt.Printf("\n")
memory, err := memory.Get()
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
return
}
fmt.Printf("[INFO] memory total: %d bytes\n", memory.Total)
fmt.Printf("[INFO] memory used: %d bytes\n", memory.Used)
before, err := cpu.Get()
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
return
}
time.Sleep(time.Duration(500) * time.Millisecond)
after, err := cpu.Get()
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
return
}
total := float64(after.Total - before.Total)
fmt.Printf("[INFO] cpu used : %f%%\n", float64(after.User-before.User)/total*100)
fmt.Printf("[INFO] cpu system: %f%%\n", float64(after.System-before.System)/total*100)
fmt.Printf("[INFO] cpu idle : %f%%\n", float64(after.Idle-before.Idle)/total*100)
fmt.Printf("\n")
}
// Initial loop etc
func main() {
log.Println("[INFO] Setting up execution environment")
@@ -371,6 +408,8 @@ func main() {
},
}
getStats()
if (len(httpProxy) > 0 || len(httpsProxy) > 0) && baseUrl != "http://shuffle-backend:5001" {
client = &http.Client{}
} else {
+8 -6
View File
@@ -839,9 +839,10 @@ func shutdown(executionId, workflowId string) {
log.Printf("[INFO] Failed abort request: %s", err)
}
log.Printf("[INFO] Finished shutdown (after 15 seconds).")
sleepDuration := 0
log.Printf("[INFO] Finished shutdown (after %d seconds).", sleepDuration)
// Allows everything to finish in subprocesses
time.Sleep(time.Duration(15) * time.Second)
time.Sleep(time.Duration(sleepDuration) * time.Second)
os.Exit(3)
}
@@ -862,9 +863,10 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, env []
log.Printf("[WARNING] Empty self container id, continue without NetworkMode")
}
if cleanupEnv == "true" {
hostConfig.AutoRemove = true
}
// Removing because log extraction should happen first
//if cleanupEnv == "true" {
// hostConfig.AutoRemove = true
//}
config := &container.Config{
Image: image,
@@ -892,7 +894,7 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, env []
return err
}
log.Printf("[INFO] Container %s is created for %s", cont.ID, identifier)
log.Printf("[INFO] Container %s was created for %s", cont.ID, identifier)
containerIds = append(containerIds, cont.ID)
return nil
}