8000 hash lb · open-lambda/open-lambda@5218d91 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit 5218d91

Browse files
committed
hash lb
1 parent 4749469 commit 5218d91

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

boss.json.overrides

Copy file name to clipboard
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"disk_size_gb": 30,
2020
"machine_type": "e2-medium"
2121
},
22-
"lb": "sharding",
22+
"lb": "random",
2323
"max_group": 5,
2424
"platform": "azure",
2525
"scaling": "manual",

src/boss/cloudvm/worker.go

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -474,50 +474,38 @@ func (pool *WorkerPool) RunLambda(w http.ResponseWriter, r *http.Request) {
474474
}
475475
// fmt.Println("Debug 1")
476476
var worker *Worker
477+
var img string
478+
urlParts := getURLComponents(r)
479+
if len(urlParts) < 2 {
480+
w.Header().Set("Access-Control-Allow-Origin", "*")
481+
w.WriteHeader(http.StatusInternalServerError)
482+
w.Write([]byte("expected invocation format: /run/<lambda-name>"))
483+
return
484+
}
485+
img = urlParts[1]
486+
thisTask = img
477487
if loadbalancer.Lb.LbType == loadbalancer.Random {
478488
// fmt.Println("Debug 2")
479489
worker = <-pool.queue
480490
pool.queue <- worker
481491
// fmt.Println("Debug 3")
482-
urlParts := getURLComponents(r)
483-
if len(urlParts) < 2 {
484-
w.Header().Set("Access-Control-Allow-Origin", "*")
485-
w.WriteHeader(http.StatusInternalServerError)
486-
w.Write([]byte("expected invocation format: /run/<lambda-name>"))
487-
return
488-
}
489-
img := urlParts[1]
490-
thisTask = img
491492
} else {
492493
// TODO: what if the designated worker isn't up yet?
493494
// Current solution: then randomly choose one that is up
494495
// step 1: get its dependencies
495-
urlParts := getURLComponents(r)
496+
496497
var pkgs []string
497-
if len(urlParts) < 2 {
498-
w.Header().Set("Access-Control-Allow-Origin", "*")
498+
// components represent run[0]/<name_of_sandbox>[1]/<extra_things>...
499+
// ergo we want [1] for name of sandbox
500+
// TODO: if user changes the code, one worker will know that, boss cannot know that. How to handle this?
501+
502+
pkgs, err = getPkgs(img)
503+
if err != nil {
499504
w.WriteHeader(http.StatusInternalServerError)
500-
w.Write([]byte("expected invocation format: /run/<lambda-name>"))
505+
w.Write([]byte("failed to get function's dependency packages"))
501506
return
502-
} else {
503-
// components represent run[0]/<name_of_sandbox>[1]/<extra_things>...
504-
// ergo we want [1] for name of sandbox
505-
// TODO: if user changes the code, one worker will know that, boss cannot know that. How to handle this?
506-
if len(urlParts) == 2 {
507-
img := urlParts[1]
508-
thisTask = img
509-
pkgs, err = getPkgs(img)
510-
if err != nil {
511-
w.WriteHeader(http.StatusInternalServerError)
512-
w.Write([]byte("failed to get function's dependency packages"))
513-
return
514-
}
515-
} else {
516-
w.WriteHeader(http.StatusInternalServerError)
517-
w.Write([]byte("expected invocation format: /run/<lambda-name>"))
518-
return
519-
}
520507
}
508+
521509
var targetGroups []int
522510
var targetGroup int
523511
// Sharding: get the target group
@@ -530,6 +518,11 @@ func (pool *WorkerPool) RunLambda(w http.ResponseWriter, r *http.Request) {
530518
}
531519
}
532520

521+
if loadbalancer.Lb.LbType == loadbalancer.Hash {
522+
targetGroup = loadbalancer.HashGetGroup(img)
523+
targetGroups = append(targetGroups, targetGroup)
524+
}
525+
533526
// KMeans/KModes: get the target group
534527
if loadbalancer.Lb.LbType == loadbalancer.KModes || loadbalancer.Lb.LbType == loadbalancer.KMeans {
535528
// get a vector

src/boss/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func LoadConf(path string) error {
7171
if Conf.Lb == "kmodes" {
7272
loadbalancer.InitLoadBalancer(loadbalancer.KModes, Conf.MaxGroup)
7373
}
74+
if Conf.Lb == "hash" {
75+
loadbalancer.InitLoadBalancer(loadbalancer.Hash, Conf.MaxGroup)
76+
}
7477

7578
return checkConf()
7679
}

src/boss/loadbalancer/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const (
1313
KMeans = 1
1414
KModes = 2
1515
Sharding = 3
16+
Hash = 4
1617
)
1718

1819
const (
@@ -73,6 +74,9 @@ func InitLoadBalancer(lbType int, maxGroup int) {
7374
log.Fatalf(err.Error())
7475
}
7576
}
77+
if lbType == Hash {
78+
initHasher()
79+
}
7680
}
7781
Lb = &LoadBalancer{
7882
LbType: lbType,

0 commit comments

Comments
 (0)
0