@@ -474,50 +474,38 @@ func (pool *WorkerPool) RunLambda(w http.ResponseWriter, r *http.Request) {
474
474
}
475
475
// fmt.Println("Debug 1")
476
476
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
477
487
if loadbalancer .Lb .LbType == loadbalancer .Random {
478
488
// fmt.Println("Debug 2")
479
489
worker = <- pool .queue
480
490
pool .queue <- worker
481
491
// 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
491
492
} else {
492
493
// TODO: what if the designated worker isn't up yet?
493
494
// Current solution: then randomly choose one that is up
494
495
// step 1: get its dependencies
495
- urlParts := getURLComponents ( r )
496
+
496
497
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 {
499
504
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 " ))
501
506
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
- }
520
507
}
508
+
521
509
var targetGroups []int
522
510
var targetGroup int
523
511
// Sharding: get the target group
@@ -530,6 +518,11 @@ func (pool *WorkerPool) RunLambda(w http.ResponseWriter, r *http.Request) {
530
518
}
531
519
}
532
520
521
+ if loadbalancer .Lb .LbType == loadbalancer .Hash {
522
+ targetGroup = loadbalancer .HashGetGroup (img )
523
+ targetGroups = append (targetGroups , targetGroup )
524
+ }
525
+
533
526
// KMeans/KModes: get the target group
534
527
if loadbalancer .Lb .LbType == loadbalancer .KModes || loadbalancer .Lb .LbType == loadbalancer .KMeans {
535
528
// get a vector
0 commit comments