Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.

Latest commit

 

History

History
217 lines (195 loc) · 8.68 KB

cell-scaling.md

File metadata and controls

217 lines (195 loc) · 8.68 KB

Scaling up/down cells

Each component within the cells can be scaled up or down. Cellery supports auto scaling with Horizontal pod autoscaler, and Zero-scaling. In addition, its possible to scale components of cells and composites manually.

This README includes,

A component can have either Autoscaling policy or zero scaling policy. Based on that, the underneath autoscaler will be determined. Generally the autoscaling policy has minimum replica count greater than 0, and hence the horizontal pod autoscaler will be used to scale up and down the components. The zero-scaling has minimum replica count 0, and hence when the component did not get any request, the component will be terminated and it will be running back once a request was directed to the component.

Scale with HPA

If a component has a scaling policy as Autoscaling policy as explained here, the specified component will be scaled with horizontal pod autoscaler.

Enable HPA

By default local, and existing kubernetes cluster will not have the metrics server deployed for horizontal pod autoscaler to work. GCP has it by default. Therefore, if you are using local, or existing kubernetes cluster, then you can enable by following below command. This also can be performed by modify setup.

    cellery setup modify --hpa=enable

Syntax for scaling with HPA

cellery:Component petComponent = {
        name: "pet-service",
        source: {
            image: "docker.io/isurulucky/pet-service"
        },
        ingresses: {
            stock: <cellery:HttpApiIngress>{ port: 9090,
                context: "petsvc",
                definition: {
                    resources: [
                        {
                            path: "/*",
                            method: "GET"
                        }
                    ]
                }
            }
        },
        resources: {
            limits: {
                memory: "128Mi",
                cpu: "500m"
            }
        },
        scaling: {
            policy: <AutoScalingPolicy> {
                minReplicas: 1,
                maxReplicas: 10,
                metrics: {
                    cpu: <cellery:Value>{ threshold : "500m" },
                    memory: <cellery:Percentage> { threshold : 50 }
                }
            },
            override: true
        }
    };

The above component pet-service has an autoscaling policy with minimum replica count 1 and maximum replica count 10. Further, threshold values for cpu and memory is provided to decide upong scaling decisions. For detailed syntax, refer here.

Export policy

Once the above component is wrapped into a cell/composite and deployed in Cellery runtime, the build time auto scaling policy will be applied. Often the build time autoscaling policy is not sufficient, and depends on the runtime environment and available resources, the devops may require to re-evaluate the autoscaling policies. Therefore, the exporting policy will be helpful to understand the current autoscaling policy that is applied to the component. This can be performed as shown below.

For a cell:

    cellery export-policy autoscale cell pet-be-instance -f pet-be-policy.yaml

For a composite:

    cellery export-policy autoscale composite pet-be-instance -f pet-be-policy.yaml

This will result in a yaml structured file similar to the following:

components:
- name: controller
  scalingPolicy:
    hpa:
      minReplicas: 1
      maxReplicas: 5
      metrics:
      - resource:
          name: memory
          targetAverageValue: "64Mi"
        type: Resource
- name: catalog
  scalingPolicy:
    replicas: 1
- name: orders
  scalingPolicy:
    replicas: 1
- name: customers
  scalingPolicy:
    hpa:
      minReplicas: 1
      maxReplicas: 3
      metrics:
        - resource:
            name: cpu
            targetAverageUtilization: 50
          type: Resource
gateway:
  scalingPolicy:
    replicas: 1

In this exported autoscale policy, the components controller and customers have autoscaling policies defined. For the components catalog and orders do not have autoscaling policies, but only the replica count defined. The gateway also has a flat scaling policy. These autoscaling policies and fixed replica counts can be modified and re-applied using the Apply Policy command, which will get reflected in the running instances.

Apply policy

Once the policy is exported, the policy can be evaluated, and modified based on the requirement. The modified policy can be applied to the running cell instance. Note, if the component is defined with scaling policy with override parameter false as shown syntax, the policy cannot be applied in the runtime.

For a cell:

 cellery apply-policy autoscale cell petfe pet-fe-modified.yaml

For a composite:

 cellery apply-policy autoscale composite petfe pet-fe-modified.yaml

Zero-scaling

Zero scaling is powered by Knative. The zero-scaling have minimum replica count 0, and hence when the component did not get any request, the component will be terminated and it will be running back once a request was directed to the component.

Enable zero-scaling

By default, the cellery installations have zero-scaling disabled. Therefore, if you want to zero scale your components, you have to enable zero-scaling as shown below.

 cellery setup modify --scale-to-zero=enable

Syntax for zero-scaling

cellery:Component petComponent = {
        name: "pet-service",
        source: {
            image: "docker.io/isurulucky/pet-service"
        },
        ingresses: {
            stock: <cellery:HttpApiIngress>{ port: 9090,
                context: "petsvc",
                definition: {
                    resources: [
                        {
                            path: "/*",
                            method: "GET"
                        }
                    ]
                }
            }
        },
        scaling: {
            policy: <ZeroScalingPolicy> {
                maxReplicas: 10,
                concurrencyTarget: 50
            }
        }
    };

The above component pet-service has a zero scaling policy (minimum replica count 0) with maximum replica count 10. Further, scaling with be performed based on concurrent requests for the component, and pet-service has concurrency threshold 50. For detailed syntax, refer here.

Just build and run the cell with this scaling configuration for the component, to try out the zero scaling functionality.

Manual scaling

Cell and composite components can be scaled up/down manually. This is particularly useful if there is no autoscaling policy attached for a component. First, export the scale policies for the given cell. Now, modify the exported policy by changing scalingPolicy.replicas under the selected component:

components:
- name: catalog
  scalingPolicy:
    replicas: 4
- name: orders
  scalingPolicy:
    replicas: 1
gateway:
  scalingPolicy:
    replicas: 2

In the exported scale policy shown above, replicas for catalog component is set to 4 and for gateway its 2. Apply the scale policy again so that the changes are reflected.

#What's Next?