Function Scaling and Triggers

Scaling is one of the core features of a FaaS or Serverless platform.

OpenFunction defines function scaling in ScaleOptions and defines triggers to activate function scaling in Triggers

ScaleOptions

You can define unified function scale options for sync and async functions like below which will be valid for both sync and async functions:

  1. apiVersion: core.openfunction.io/v1beta1
  2. kind: Function
  3. metadata:
  4. name: function-sample
  5. spec:
  6. serving:
  7. scaleOptions:
  8. minReplicas: 0
  9. maxReplicas: 10

Usually simply defining minReplicas and maxReplicas is not enough for async functions. You can define seperate scale options for async functions like below which will override the minReplicas and maxReplicas.

You can find more details of async function scale options in KEDA ScaleObject Spec and KEDA ScaledJob Spec.

  1. apiVersion: core.openfunction.io/v1beta1
  2. kind: Function
  3. metadata:
  4. name: function-sample
  5. spec:
  6. serving:
  7. scaleOptions:
  8. keda:
  9. scaledObject:
  10. pollingInterval: 15
  11. minReplicaCount: 0
  12. maxReplicaCount: 10
  13. cooldownPeriod: 60
  14. advanced:
  15. horizontalPodAutoscalerConfig:
  16. behavior:
  17. scaleDown:
  18. stabilizationWindowSeconds: 45
  19. policies:
  20. - type: Percent
  21. value: 50
  22. periodSeconds: 15
  23. scaleUp:
  24. stabilizationWindowSeconds: 0

You can also set advanced scale options for Knative sync functions too which will override the minReplicas and maxReplicas.

You can find more details of the Knative sync function scale options here

  1. apiVersion: core.openfunction.io/v1beta1
  2. kind: Function
  3. metadata:
  4. name: function-sample
  5. spec:
  6. serving:
  7. scaleOptions:
  8. knative:
  9. autoscaling:
  10. autoscaling.knative.dev/min-scale: 0
  11. autoscaling.knative.dev/max-scale: 10
  12. autoscaling.knative.dev/initial-scale: "1"
  13. autoscaling.knative.dev/scale-down-delay: "0"
  14. autoscaling.knative.dev/window: "60s"
  15. autoscaling.knative.dev/panic-window-percentage: "10.0"
  16. autoscaling.knative.dev/metric: "concurrency"
  17. autoscaling.knative.dev/target: 100

Triggers

Triggers define how to activate function scaling for async functions. You can use triggers defined in all KEDA scalers as OpenFunction’s trigger spec.

Sync functions’ scaling is activated by various options of HTTP requests which are already defined in the previous ScaleOption section.

  1. apiVersion: core.openfunction.io/v1beta1
  2. kind: Function
  3. metadata:
  4. name: function-sample
  5. spec:
  6. serving:
  7. runtime: "async"
  8. triggers:
  9. - type: kafka
  10. metadata:
  11. topic: logs
  12. bootstrapServers: kafka-server-kafka-brokers.default.svc.cluster.local:9092
  13. consumerGroup: logs-handler
  14. lagThreshold: "20"

Last modified June 23, 2022: Add prefix to Knative scale options (#122) (303ec94)