Flow Control

Flow control mechanism controls the transmission speed to avoid microservices being overloaded. This guide shows how to use flow control with ServiceComb in the BMI application.

Before you start

Walk through Develop microservice application in minutes and have BMI application running.

Enable

  1. Add flow control dependency in pom.xml of BMI calculator service:

     <dependency>
       <groupId>org.apache.servicecomb</groupId>
       <artifactId>handler-flowcontrol-qps</artifactId>
     </dependency>
    
  2. Add handler chain and configurations of flow control in microservice.yaml of BMI calculator service:

    servicecomb:
      handler:
        chain:
          Provider:
            default: qps-flowcontrol-provider
      flowcontrol:
        Provider:
          qps:
            limit:
              gateway: 1
    

The above configurations have already set up in the code. All you need to do is to stop all BMI calculator services and then start a new one with the following command:

mvn spring-boot:run -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=qps-flowcontrol-provider -Dcse.flowcontrol.Provider.qps.limit.gateway=1"

Verification

Visit http://localhost:8889. Input a positive height and weight and then click Submit button twice or more in less than one second. You will see the web page change from the left one to the right one.

Flow control result

What’s next