Skip to content

Commit 20fffd7

Browse files
grussorussomatnar
andcommitted
Refactors ILPOffloadingPolicy; adds HEFTlessPolicy
Co-authored-by: Matteo Nardelli <matnar@gmail.com>
1 parent 1acaca3 commit 20fffd7

5 files changed

Lines changed: 571 additions & 463 deletions

File tree

internal/config/keys.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ const TRACING_OUTFILE = "tracing.outfile"
8383
const OFFLOADING_POLICY = "offloading.policy"
8484

8585
// Port used by ILP Offloading Policy for solving the ILP formulation
86-
const OFFLOADING_POLICY_ILP_OPTIMIZER_PORT = "offloading.policy.ilp.port"
86+
const OFFLOADING_POLICY_OPTIMIZER_PORT = "offloading.policy.optimizer.port"
8787

8888
// IP address / hostname used by ILP Offloading Policy for solving the ILP formulation
89-
const OFFLOADING_POLICY_ILP_OPTIMIZER_HOST = "offloading.policy.ilp.host"
89+
const OFFLOADING_POLICY_OPTIMIZER_HOST = "offloading.policy.optimizer.host"
9090

9191
// Number of times a scheduling plan can be reused before being re-computed
9292
const OFFLOADING_POLICY_ILP_PLACEMENT_TTL = "offloading.policy.ilp.placement.ttl"
9393

9494
// Monetary computation cost per region (Map: string -> float)
95-
const OFFLOADING_POLICY_ILP_REGION_COST = "offloading.policy.ilp.region.cost"
95+
const OFFLOADING_POLICY_REGION_COST = "offloading.policy.region.cost"
9696

9797
// Weight of objective terms in the ILP offloading policy
9898
const OFFLOADING_POLICY_ILP_OBJ_WEIGHT_VIOLATIONS = "offloading.policy.ilp.obj.violations"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package workflow
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"github.com/serverledge-faas/serverledge/internal/config"
8+
"log"
9+
"net/http"
10+
)
11+
12+
type HEFTlessPolicy struct{}
13+
14+
func (policy *HEFTlessPolicy) Evaluate(r *Request, p *Progress) (OffloadingDecision, error) {
15+
16+
completed := 0
17+
18+
if p == nil || !r.CanDoOffloading || len(p.ReadyToExecute) == 0 {
19+
return OffloadingDecision{Offload: false}, nil
20+
}
21+
22+
for _, s := range p.Status {
23+
if s == Executed {
24+
completed++
25+
}
26+
}
27+
28+
if completed > 0 {
29+
placement, found := getCachedSolution(r)
30+
if found {
31+
log.Printf("Reusing cached placement\n")
32+
return computeDecisionFromPlacement(*placement, p, r), nil
33+
} else {
34+
// No rescheduling admitted
35+
return OffloadingDecision{Offload: false}, fmt.Errorf("HEFTless does not support re-scheduling during execution")
36+
}
37+
}
38+
39+
params := prepareParameters(r, p)
40+
41+
// Serialize to JSON
42+
jsonData, err := json.Marshal(params)
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
// Create POST request
48+
optimizerHost := config.GetString(config.OFFLOADING_POLICY_OPTIMIZER_HOST, "localhost")
49+
optimizerPort := config.GetInt(config.OFFLOADING_POLICY_OPTIMIZER_PORT, 8080)
50+
url := fmt.Sprintf("http://%s:%d/heftless", optimizerHost, optimizerPort)
51+
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
52+
if err != nil {
53+
return OffloadingDecision{Offload: false}, fmt.Errorf("creating request: %w", err)
54+
}
55+
req.Header.Set("Content-Type", "application/json")
56+
57+
// Send the request
58+
resp, err := httpClient.Do(req)
59+
if err != nil {
60+
fmt.Println(err)
61+
return OffloadingDecision{Offload: false}, fmt.Errorf("sending request: %w", err)
62+
}
63+
defer resp.Body.Close()
64+
65+
statusCode := resp.StatusCode
66+
if statusCode != 200 {
67+
return OffloadingDecision{Offload: false}, fmt.Errorf("scheduling failed with status code %d", statusCode)
68+
}
69+
70+
// Read and print response
71+
var placement taskPlacement
72+
err = json.NewDecoder(resp.Body).Decode(&placement)
73+
if err != nil {
74+
fmt.Println(err)
75+
return OffloadingDecision{Offload: false}, fmt.Errorf("decoding response: %w", err)
76+
}
77+
78+
cacheSolution(r, &placement, 9999)
79+
80+
for k, v := range placement {
81+
fmt.Printf("Task: %s -> %s \n", k, v)
82+
}
83+
84+
// parse results and make a decision
85+
return computeDecisionFromPlacement(placement, p, r), nil
86+
}

0 commit comments

Comments
 (0)