Giter VIP home page Giter VIP logo

faas-idler's Introduction

faas-idler

[Build Status]

Scale OpenFaaS functions to zero replicas after a period of inactivity

Premise: functions (Deployments) can be scaled to 0/0 replicas from 1/1 or N/N replicas when they are not receiving traffic. Traffic is observed from Prometheus metrics collected in the OpenFaaS API Gateway.

Scaling to zero requires an "un-idler" or a blocking HTTP proxy which can reverse the process when incoming requests attempt to access a given function. This is done through the OpenFaaS API Gateway through which every incoming call passes - see Add feature: scale from zero to 1 replicas #685.

faas-idler is implemented as a controller which polls Prometheus metrics on a regular basis and tries to reconcile a desired condition - i.e. zero replicas -> scale down API call.

Building

The build requires Docker and builds a local Docker image.

TAG=0.1.9 make build
TAG=0.1.9 make push

Usage

Quick start

Swarm:

docker stack deploy func -c docker-compose.yml

Kubernetes

kubectl apply -f faas-idler-dep.yml

Now decorate some functions with the label: com.openfaas.scale.zero: true and watch the idler scale them to zero. You should also change the -dry-run flag to false. For example:

faas-cli store deploy figlet --label "com.openfaas.scale.zero=true"

Configuration

  • Environmental variables:

On Kubernetes the gateway_url needs to contain the suffix of the namespace you picked at deploy time. This is usually .openfaas and is pre-configured with a default.

Try using the ClusterIP/Cluster Service instead and port 8080.

env_var description
gateway_url The URL for the API gateway i.e. http://gateway:8080 or http://gateway.openfaas:8080 for Kubernetes
prometheus_host host for Prometheus
prometheus_port port for Prometheus
inactivity_duration i.e. 10m (Golang duration)
reconcile_interval i.e. 30s (default value)
secret_mount_path default /var/secrets/, path from which basic-auth-user and basic-auth-password files are read
write_debug default false, set to true to enable verbose logging for debugging / troubleshooting
  • Command-line args

-dry-run - don't send scaling event

How it works:

gateway_function_invocation_total is measured for activity over duration i.e. 1h of inactivity (or no HTTP requests)

Logs

You can view the logs to show reconciliation in action.

kubectl logs -n openfaas -f deploy/faas-idler

faas-idler's People

Contributors

alexellis avatar cedricvidal avatar ivanayov avatar martindekov avatar rdimitrov avatar rgee0 avatar

Watchers

 avatar  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.