Git Product home page Git Product logo

slimfaas's Introduction

SlimFaas : The slimest and simplest Function As A Service Continuous Integration Quality Gate Reliability Security Code Corevage Docker SlimFaas

SlimFaas.png

Why use SlimFaas ?

  • Scale to 0 after a period of inactivity
  • Synchronous HTTP calls
  • Asynchronous HTTP calls
    • Allows you to limit the number of parallel HTTP requests for each underlying function
  • Retry: 3 times with graduation: 2 seconds, 4 seconds, 8 seconds
  • Simple to install: just deploy a standard pod
    • No impact on your current kubernetes manifests: just add an annotation to the pod you want to auto-scale
  • Very Slim and very Fast

slim-faas-ram-cpu.png

Getting Started with Kubernetes

To test slimfaas on your local machine by using kubernetes with Docker Desktop, please use these commands:

git clone https://github.com/AxaFrance/slimfaas.git
cd slimfaas/demo
kubectl create namespace slimfaas-demo
kubectl config set-context --current --namespace=slimfaas-demo
# Create a custom service account for slimfaas
# SlimFaas require to ba able to request Kubernetes API
kubectl apply -f slimfaas-serviceaccount.yml
# Install slimfaas pod
kubectl apply -f deployment-slimfaas.yml
# Install three instances of fibonacci functions
# fibonacci1, fibonacci2 and fibonacci3
kubectl apply -f deployment-functions.yml

Now, you can access your pod via SlimFaas proxy:

Synchronous way:

Asynchronous way:

Just wake up function:

Enjoy slimfaas !!!!

Getting Started with docker-compose

To test slimfaas on your local machine by using kubernetes with Docker Desktop, please use these commands:

git clone https://github.com/AxaFrance/slimfaas.git
cd slimfaas
docker-compose up

Now, you can access your pod via SlimFaas proxy:

Enjoy slimfaas !!!!

How it works

SlimFaas act as an HTTP proxy with 2 modes:

Synchrounous HTTP call

sync_http_call.PNG

Asynchrounous HTTP call

async_http_call.PNG

Wake HTTP call

How to install

  1. Add SlimFaas annotations to your pods
  2. Add SlimFaas pod
  3. Have fun !

sample-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: fibonacci1
spec:
  selector:
    matchLabels:
      app: fibonacci1
  template:
    metadata:
      labels:
        app: fibonacci1
      annotations:
        # Just add SlimFaas annotation to your pods and that's it !
        SlimFaas/Function: "true" 
        SlimFaas/ReplicasMin: "0"
        SlimFaas/ReplicasAtStart: "1"
        SlimFaas/ReplicasStartAsSoonAsOneFunctionRetrieveARequest: "true"
        SlimFaas/TimeoutSecondBeforeSetReplicasMin: "300"
        SlimFaas/NumberParallelRequest : "10"
    spec:
      serviceAccountName: default
      containers:
        - name: fibonacci1
          image: docker.io/axaguildev/fibonacci:latest
          resources:
            limits:
              memory: "96Mi"
              cpu: "50m"
            requests:
              memory: "96Mi"
              cpu: "10m"
          ports:
            - containerPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: slimfaas
spec:
  selector:
    matchLabels:
      app: slimfaas
  template:
    metadata:
      annotations:
        prometheus.io/path: /metrics
        prometheus.io/port: '5000'
        prometheus.io/scrape: 'true'
      labels:
        app: slimfaas
    spec:
      serviceAccountName: admin # Use a service account with admin role
      containers:
        - name: slimfaas
          image: docker.io/axaguildev/slimfaas:latest
          livenessProbe:
            httpGet:
              path: /health
              port: 5000
            initialDelaySeconds: 1
            periodSeconds: 10
            timeoutSeconds: 8
          env:
            - name: BASE_FUNCTION_URL
              value: "http://{function_name}.default.svc.cluster.local:8080"
            - name: ASPNETCORE_URLS
              value: http://+:5000
            - name: NAMESPACE
              value: "default"
            # If you want to use Redis use this env variable and comment MOCK_REDIS
            #- name: REDIS_CONNECTION_STRING 
            #  value: "redis-ha-haproxy:6379"
            - name: MOCK_REDIS
              value: "true"
            # If your are not on kubernetes for example docker-compose, you can use this env variable, but you will lose auto-scale
            #- name: MOCK_KUBERNETES_FUNCTIONS 
            #  value: "{\"Functions\":[{\"Name\":\"kubernetes-bootcamp1\",\"NumberParallelRequest\":1}]}"
          resources:
            limits:
              memory: "76Mi"
              cpu: "400m"
            requests:
              memory: "76Mi"
              cpu: "250m"
          ports:
            - containerPort: 5000

SlimFaas Annotations with defaults values

  • SlimFaas/Function: "true"
    • Activate SlimFaas on this pod, so your pod will be auto-scaled
  • SlimFaas/ReplicasMin: "0"
    • Scale down to this value after a period of inactivity
  • SlimFaas/ReplicasAtStart: "1"
    • Scale up to this value at start
  • SlimFaas/ReplicasStartAsSoonAsOneFunctionRetrieveARequest: "true"
    • Scale up this pod as soon as one function retrieve a request
  • SlimFaas/TimeoutSecondBeforeSetReplicasMin: "300"
    • Scale down to SlimFaas/ReplicasMin after this period of inactivity in seconds
  • SlimFaas/NumberParallelRequest : "10"
    • Limit the number of parallel HTTP requests for each underlying function

Why SlimFaas ?

We used OpenFaas for a long time and we love it. But we encountered many OpenFaas issues :

  • Kubernetes scripts are tightly coupled to OpenFaas syntax
  • OpenFaas pro is too expensive for our projects
  • OpenFaas needs to be installed on a dedicated namespace and configuration was intricate
  • OpenFaas monitoring was not compatible with our monitoring solution
  • It requires to configure well NATS for managing fail-over
  • Queue configuration is not easy
  • The aggressive removing of of old images from docker.io by OpenFaas team in April 20023 got us some production issues

We would like to use Knative but:

  • We cannot use it because of some internal constraints and security issues.

So we decided to create SlimFaas to have a quick and simple replacement proxy solution that can expose Prometheus metrics. Now we have a solution not coupled to anything. SlimFaas is simple, light, fast and plug and play !

How it works ?

Instead of creating many pods, SlimFaas use internally many workers in the same pod:

  • SlimWorker: Manage asynchronous HTTP requests calls to underlying functions
  • HistorySynchronisationWorker: Manage history of HTTP requests between the pod and kubernetes
  • ReplicasSynchronizationWorker: Manage replicas synchronization between the pod and kubernetes
  • MasterWorker: Elect a master pod to manage kubernetes scale up and down
  • ReplicasScaleWorker: If master, then scale up and down kubernetes pods

Build with .NET

Why .NET ?

What Next ?

  1. Public Open Source
  2. Add a build version without any redis dependencies and allow SlimFaas to manage internal queue
  3. Scale up dynamically from SlimFaas
  4. Upgrade to .NET8 using AOT => lighter and faster

slimfaas's People

Contributors

g7ed6e avatar guillaume-chervet avatar tlemarchand avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.