Skip to content

Commit b7d8e09

Browse files
committed
Architecture-aware mechanisms and LB policies
1 parent 24ba67d commit b7d8e09

66 files changed

Lines changed: 3357 additions & 920 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/run_tests.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Run Tests CI
2+
3+
on:
4+
push:
5+
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Setup Go
13+
uses: actions/setup-go@v3
14+
with:
15+
go-version: "1.24.0"
16+
17+
- name: Checkout branch
18+
uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.ref_name }}
21+
22+
- name: Install dependencies
23+
run: make
24+
25+
- name: Run tests
26+
run: make unit-test && make test

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ serverledge-cli:
1414
executor:
1515
CGO_ENABLED=0 $(GO) build -o $(BIN)/$@ cmd/$@/executor.go
1616

17-
DOCKERHUB_USER=grussorusso
17+
DOCKERHUB_USER=fmuschera
1818
images: image-python310 image-nodejs17ng image-base
1919
image-python310:
2020
docker build -t $(DOCKERHUB_USER)/serverledge-python310 -f images/python310/Dockerfile .
@@ -28,8 +28,16 @@ push-images:
2828
docker push $(DOCKERHUB_USER)/serverledge-base
2929
docker push $(DOCKERHUB_USER)/serverledge-nodejs17ng
3030

31+
# Runs integration tests (all tests EXCEPT unit tests)
3132
test:
32-
go test -v ./...
33+
$(GO) test -v $(shell $(GO) list ./... | grep -Ev 'internal/container|examples')
3334

34-
.PHONY: serverledge serverledge-cli lb executor test images
35+
# Runs only unit tests
36+
unit-test:
37+
go test -v -short ./internal/container/... ./internal/lb/...
38+
39+
.PHONY: serverledge serverledge-cli lb executor test unit-test integration-test images
40+
41+
clean:
42+
@test -n "$(BIN)" && [ -d "$(BIN)" ] && rm -rf $(BIN) || { echo "Invalid BIN directory: $(BIN)"; exit 1; } && go clean -testcache
3543

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Start a local Serverledge node:
6969

7070
Register a function `func` from example python code (the handler is formatted like this: $(filename).$(functionName)):
7171

72-
$ bin/serverledge-cli create -f func --memory 600 --src examples/hello.py --runtime python310 --handler "hello.handler"
72+
$ bin/serverledge-cli create -f func --memory 600 --src examples/hello.py --runtime python314 --handler "hello.handler"
7373

7474
Register a function `func` from example javascript code (the handler is formatted like this: $(filename) and the name of the function is "handler"):
7575

cmd/lb/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/serverledge-faas/serverledge/internal/node"
65
"log"
76
"os"
87
"os/signal"
98
"time"
109

10+
"github.com/serverledge-faas/serverledge/internal/mab"
11+
"github.com/serverledge-faas/serverledge/internal/node"
12+
1113
"golang.org/x/net/context"
1214

1315
"github.com/labstack/echo/v4"
@@ -59,5 +61,6 @@ func main() {
5961
// Register a signal handler to cleanup things on termination
6062
registerTerminationHandler(e)
6163

64+
mab.InitBanditManager()
6265
lb.StartReverseProxy(e, myArea)
6366
}

examples/HelloFunction.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.test;
2+
3+
// The compiled jar used by serverledge-cli is in ./java_build/target
4+
5+
6+
import java.util.Map;
7+
import java.util.HashMap;
8+
9+
10+
public class HelloFunction {
11+
12+
13+
public Map<String, Object> handler(Object params, Map<String, Object> context) {
14+
// Test output capture (stdout)
15+
System.out.println("Log: Iniziata esecuzione Java Function!");
16+
System.out.println("Log: Parametri ricevuti: " + params);
17+
18+
// Test output capture (stderr)
19+
System.err.println("[DEBUG]: This is a debug message on stderr");
20+
21+
22+
Map<String, Object> result = new HashMap<>();
23+
result.put("message", "Hello from the Java default runtime of Serverledge!");
24+
result.put("received_params", params);
25+
result.put("java_version", System.getProperty("java.version"));
26+
27+
return result;
28+
}
29+
}

examples/go-example/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EXAMPLE OF MAKEFILE
2+
3+
AMD64_BIN=handler_amd64
4+
ARM64_BIN=handler_arm64
5+
6+
all: $(AMD64_BIN) $(ARM64_BIN)
7+
8+
$(AMD64_BIN):
9+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o $(AMD64_BIN) main.go
10+
11+
$(ARM64_BIN):
12+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o $(ARM64_BIN) main.go
13+
14+
zip: all
15+
zip -j go-function.zip $(AMD64_BIN) $(ARM64_BIN)
16+
17+
clean:
18+
rm -f $(AMD64_BIN) $(ARM64_BIN) go-function.zip
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Building Go Functions for Serverledge
2+
3+
To ensure your Go function runs correctly on Serverledge's lightweight Alpine containers (avoiding `glibc` vs `musl` issues) and supports multi-architecture clusters (x86 & ARM), follow these build steps.
4+
5+
## 1. Static Compilation
6+
You must disable CGO to make the executable self-contained and compatible with any Linux distribution (including Alpine and Scratch).
7+
You can check the example Makefile as well.
8+
9+
### Create executables for both architectures (run **both** commands)
10+
```bash
11+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o handler_amd64 main.go
12+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o handler_arm64 main.go
13+
```
14+
Removing debugging information is not strictly necessary, but may help producing smaller executables.
15+
16+
## 2. Packaging the fat zip
17+
```bash
18+
zip -j function.zip handler_amd64 handler_arm64
19+
```
20+
21+
## 3. Deploy to Serverledge
22+
```bash
23+
# create the function
24+
bin/serverledge-cli create \
25+
-f gofunc \
26+
--memory 300 \
27+
--src examples/go-example/go-function.zip \
28+
--runtime go125
29+
30+
# and then execute it
31+
bin/serverledge-cli invoke \
32+
-f gofunc \
33+
-p "name:Serverledge User" \
34+
-p "num:127"
35+
36+
# Expected output
37+
{
38+
"Success": true,
39+
"Result": "{\"message\":\"Hello Serverledge User\",\"number\":127,\"is_prime\":true}",
40+
"ResponseTime": 0.397966139,
41+
"IsWarmStart": false,
42+
"InitTime": 0.3957812,
43+
"QueueingTime": 0,
44+
"OffloadLatency": 0,
45+
"Duration": 0.002184848000000017,
46+
"Output": ""
47+
}
48+
```
49+
50+
### Or with output capture enabled
51+
```bash
52+
bin/serverledge-cli invoke \
53+
-f gofunc \
54+
-p "name:Serverledge User" \
55+
-p "num:127" \
56+
-o # flag to capture the output
57+
58+
# Expected output
59+
{
60+
"Success": true,
61+
"Result": "{\"message\":\"Hello Serverledge User\",\"number\":127,\"is_prime\":true}",
62+
"ResponseTime": 0.001020982,
63+
"IsWarmStart": true,
64+
"InitTime": 0.000054193,
65+
"QueueingTime": 0,
66+
"OffloadLatency": 0,
67+
"Duration": 0.000966691,
68+
"Output": "2025/12/01 11:12:46 Processing request for user: Serverledge User...\n2025/12/01 11:12:46 Checked number: 127 (Prime: true)\n"
69+
}
70+
```
4.48 MB
Binary file not shown.

examples/go-example/go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module go-example
2+
3+
go 1.25
4+
5+
// TODO: THIS HAS TO BE REMOVED IF THIS IS EVER MERGED TO THE MAIN REPOSITORY
6+
replace github.com/serverledge-faas/serverledge => github.com/FilippoMuschera/serverledge-tesi v0.0.0-20251201113838-6fd3cf13f0a4
7+
8+
require github.com/serverledge-faas/serverledge v0.1.0

examples/go-example/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.com/FilippoMuschera/serverledge-tesi v0.0.0-20251201113838-6fd3cf13f0a4/go.mod h1:i84eEsGrw4XoYgA3zsiyFOk8bV7oA6S4LLR8137QvNE=

0 commit comments

Comments
 (0)