Skip to content

Commit

Permalink
Merge pull request #2 from alanpjohn/benchmarking
Browse files Browse the repository at this point in the history
Benchmarking
  • Loading branch information
alanpjohn authored Sep 18, 2023
2 parents e57cfa6 + e238152 commit b7c71b3
Show file tree
Hide file tree
Showing 11 changed files with 318 additions and 216 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# ukfaasd
# ukfaas - Serverless Framework for Unikernels

OpenFaaS provider that runs Unikraft unikernels packaged as OCI images
ukfaas is a serverless framework designed to facilitate the use of Unikraft unikernels packaged as OCI (Open Container Initiative) images in serverless computing environments. This project aims to promote and incorporate unikernels into serverless computing, offering the advantages of reduced overhead and enhanced security. ukfaas achieves this by implementing the openfaas-provider interface and integrating seamlessly with all OpenFaaS tooling.

## Why ukfaas?

ukfaas bridges the gap between serverless computing and unikernels, providing a simple and efficient way to run unikernels as serverless functions. By adopting ukfaas, you can harness the benefits of unikernels, such as minimal resource consumption and rapid boot times, in your serverless applications.


## RoadMap

The project was initially built towards the completion of my dissertation project as a proof concept. The codebase requires some work and will have to grow alongside the unikraft project as that reaches maturity.

## Acknowledgments
Do check out the [unikraft](https://unikraft.org/) project!!
2 changes: 2 additions & 0 deletions cmd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func makeProviderCmd() *cobra.Command {
return err
}

go mStore.RunHealthChecks(ctx)

invokeResolver := handlers.NewInvokeResolver(fStore, mStore, networkController)

baseUserSecretsPath := path.Join(wd, "secrets")
Expand Down
15 changes: 11 additions & 4 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var testCmd = &cobra.Command{
RunE: runTest,
}

func runTest(_ *cobra.Command, _ []string) error {
func runTest(_ *cobra.Command, args []string) error {
ctx := context.Background()
fStore, err := store.NewFunctionStore(ctx, "/run/containerd/containerd.sock", "default")
if err != nil {
Expand All @@ -45,9 +45,11 @@ func runTest(_ *cobra.Command, _ []string) error {
return err
}

go mStore.RunHealthChecks(ctx)

req := types.FunctionDeployment{
Image: "unikraft.org/uk-py-faas:latest",
Service: "hello-world",
Image: args[0],
Service: "test-func",
EnvVars: map[string]string{},
Secrets: []string{},
Labels: &map[string]string{},
Expand All @@ -70,7 +72,12 @@ func runTest(_ *cobra.Command, _ []string) error {
reader := bufio.NewReader(os.Stdin)
_, _ = reader.ReadString('\n')

err = mStore.ScaleMachinesTo(ctx, req.Service, 2)
err = mStore.ScaleMachinesTo(ctx, req.Service, 0)
if err != nil {
return err
}

err = mStore.NewMachine(ctx, function)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/alanpjohn/uk-faas
go 1.20

require (
api.zip v0.1.5
github.com/containerd/containerd v1.7.2
github.com/docker/go-units v0.5.0
github.com/google/go-containerregistry v0.15.2
github.com/gorilla/mux v1.8.0
github.com/opencontainers/image-spec v1.1.0-rc4
github.com/openfaas/faasd v0.0.0-20230707124536-57baf34f5ac0
github.com/pkg/errors v0.9.1
github.com/rancher/wrangler v1.0.2
Expand All @@ -20,6 +20,7 @@ require (
)

require (
api.zip v0.1.5 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
Expand Down Expand Up @@ -118,7 +119,6 @@ require (
github.com/muesli/termenv v0.15.2 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/opencontainers/runc v1.1.7 // indirect
github.com/opencontainers/runtime-spec v1.1.0-rc.3 // indirect
github.com/opencontainers/selinux v1.11.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/network/internal/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ func (n *InternalNetworkContoller) RunHealthChecks(ctx context.Context) {
return false
default:
ip := key.(networkapi.IP)
health := checkHealth(ctx, ip, "/")
health := checkHealth(ctx, ip, "/health")
n.healthCheckTable.Store(ip, health)
delay := time.Duration(300) / time.Duration(n.instanceCount)
delay := time.Duration(300) / time.Duration(n.instanceCount+1)
time.Sleep(delay * time.Second)
}
return true
Expand Down
9 changes: 7 additions & 2 deletions pkg/network/internal/random.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package internal

import (
"log"
"fmt"
"math/rand"

networkapi "github.com/alanpjohn/uk-faas/pkg/api/network"
Expand Down Expand Up @@ -30,6 +30,9 @@ func (rlb *RandomLoadBalancer) AddInstance(ip networkapi.IP) (LoadBalancer, erro
}

func (rlb *RandomLoadBalancer) DeleteInstance(ip networkapi.IP) (LoadBalancer, error) {
if rlb.size == 0 {
return rlb, nil
}
newIpList := make([]networkapi.IP, rlb.size-1)
index := 0
for _, currIp := range rlb.ips {
Expand All @@ -38,14 +41,16 @@ func (rlb *RandomLoadBalancer) DeleteInstance(ip networkapi.IP) (LoadBalancer, e
index++
}
}
log.Printf("[RandomLoadBalancer.DeleteInstance] - Size = %v", rlb.size-1)
return &RandomLoadBalancer{
size: rlb.size - 1,
ips: newIpList,
}, nil
}

func (rlb *RandomLoadBalancer) NextInstance() (networkapi.IP, error) {
if rlb.size == 0 {
return "", fmt.Errorf("no ips for instance")
}
index := rand.Intn(int(rlb.size))
return rlb.ips[index], nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/provider/handlers/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ func MakeReadHandler(fStore *store.FunctionStore, mStore *store.MachineStore) fu

// fns, err := ListFunctions(client, lookupNamespace)
res, err := fStore.ListFunctions()
for _, function := range res {
for index, function := range res {
function.Replicas = mStore.GetReplicas(function.Name)
function.AvailableReplicas = mStore.GetAvailableReplicas(function.Name)
res[index] = function
}

if err != nil {
Expand Down
Loading

0 comments on commit b7c71b3

Please sign in to comment.