diff --git a/_data/navigation.yml b/_data/navigation.yml index de2bd7e..c477ed2 100644 --- a/_data/navigation.yml +++ b/_data/navigation.yml @@ -21,11 +21,13 @@ t: - title: "Advance microservice development" url: /docs/quick-start-advance/ children: - - title: Load balance + - title: Load Balance url: /docs/quick-start-advance/load-balance/ + - title: Flow Control + url: /docs/quick-start-advance/flow-control/ - title: Service Management url: /docs/quick-start-advance/service-management/ - - title: Distributed tracing + - title: Distributed Tracing url: /docs/quick-start-advance/distributed-tracing/ users: @@ -132,6 +134,8 @@ t: children: - title: "负载均衡" url: /cn/docs/quick-start-advance/load-balance/ + - title: "流量控制" + url: /cn/docs/quick-start-advance/flow-control/ - title: "服务治理" url: /cn/docs/quick-start-advance/service-management/ - title: "分布式调用链追踪" diff --git a/_docs/cn/distributed-tracing.md b/_docs/cn/distributed-tracing.md index 6ad6a64..95853a8 100644 --- a/_docs/cn/distributed-tracing.md +++ b/_docs/cn/distributed-tracing.md @@ -28,10 +28,11 @@ last_modified_at: 2017-09-03T10:01:43-04:00 2. 在 *体质指数计算器* 的 `microservice.yaml` 文件中添加分布式追踪的处理链: ```yaml - handler: + cse: + handler: chain: - Consumer: - default: tracing-consumer + Provider: + default: tracing-provider ``` 3. 在 *体质指数界面* 的 `pom.xml` 文件中添加依赖项: @@ -47,24 +48,23 @@ last_modified_at: 2017-09-03T10:01:43-04:00 ``` -4. 在 *体质指数界面* 的`microservice.yaml` 文件中添加分布式追踪的处理链: - - ```yaml - handler: - chain: - Consumer: - default: tracing-consumer - Provider: - default: tracing-provider - ``` +体质指数应用中已配置好了上述配置项,您只需执行以下几步即可: -5. 使用 Docker 运行 *Zipkin* 分布式追踪服务: +1. 使用 Docker 运行 *Zipkin* 分布式追踪服务: ```bash docker run -d -p 9411:9411 openzipkin:zipkin ``` -修改后需要重启 *体质指数计算器* 和 *体质指数界面* 。 +2. 重启 *体质指数计算器* 微服务: + ```bash + mvn spring-boot:run -Ptracing -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=tracing-provider" + ``` + +3. 重启 *体质指数界面* 微服务: + ```bash + mvn spring-boot:run -Ptracing + ``` ## 验证 diff --git a/_docs/cn/flow-control.md b/_docs/cn/flow-control.md new file mode 100644 index 0000000..4f87b3c --- /dev/null +++ b/_docs/cn/flow-control.md @@ -0,0 +1,58 @@ +--- +title: "流量控制" +lang: cn +ref: quick-start-flow-control +permalink: /cn/docs/quick-start-advance/flow-control/ +excerpt: "介绍如何在体质指数应用中使用ServiceComb框架提供的流量控制能力" +last_modified_at: 2017-09-03T10:01:43-04:00 +--- + +{% include toc %} +流量控制机制通过控制数据传输速率来避免微服务过载运行。本指南将展示如何在 *体质指数* 应用中使用 **ServiceComb** 提供的流量控制能力。 + +## 前言 + +在您进一步阅读之前,请确保您已阅读了[微服务应用快速开发指南](/cn/docs/quick-start-bmi/),并已成功运行体质指数微服务。 + +## 开启 + +1. 在 *体质指数计算器* 的 `pom.xml` 文件中添加依赖项: + + ```xml + + io.servicecomb + handler-flowcontrol-qps + + ``` + +2. 在 *体质指数计算器* 的 `microservice.yaml` 文件中指明使用流量控制的处理链及指定流控策略: + + ```yaml + cse: + handler: + chain: + Provider: + default: qps-flowcontrol-provider + flowcontrol: + Provider: + qps: + limit: + gateway: 1 + ``` + +体质指数应用中已配置好了上述配置项,您只需关闭之前运行的 **体质指数计算器**,然后再用以下指令重新运行即可: + +```bash +mvn spring-boot:run -Pflowcontrol -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=qps-flowcontrol-provider -Dcse.flowcontrol.Provider.qps.limit.gateway=1" +``` + +## 验证 + +访问 http://localhost:8888,在身高和体重的输入框中输入正数,尝试在1秒内多次点击 *Submit* 按钮,此时就能看到网页由左侧的正常的界面变成了右侧提示由于流控受限而请求被拒的界面。 + +![流量控制效果图](/assets/images/flow-control-result.png){: .align-center} + +## 下一步 + +* 阅读[服务治理快速入门](/cn/docs/quick-start-advance/service-management/) +* 了解更多[流量控制](/cn/users/qps/)的使用方式 diff --git a/_docs/cn/load-balance.md b/_docs/cn/load-balance.md index cd28291..436da4c 100644 --- a/_docs/cn/load-balance.md +++ b/_docs/cn/load-balance.md @@ -16,38 +16,46 @@ last_modified_at: 2017-09-03T10:01:43-04:00 ## 开启 -在 *体质指数界面* 的 `microservice.yaml` 文件中添加以下内容即可开启负载均衡的能力: +1. 在 *体质指数界面* 的 `pom.xml` 文件中添加依赖项: -```yaml - handler: - chain: - Consumer: - default: loadbalance -``` + ```xml + + io.servicecomb + handler-loadbalance + + ``` -修改后需要重启体质指数界面微服务。 +2. 在 *体质指数界面* 的 `microservice.yaml` 文件中开启负载均衡的能力: -## 验证 + ```yaml + cse: + handler: + chain: + Consumer: + default: loadbalance + ``` -对 *体质指数计算器* 微服务进行水平扩展,使其运行实例数为2,即新增一个运行实例。在体质指数计算器的源代码作出如下修改: +体质指数应用中已配置好了上述配置项,您只需通过以下指令重启体质指数界面微服务即可: -1. 修改服务运行端口,避免端口冲突 +```bash +mvn spring-boot:run -Pflowcontrol -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=loadbalance" +``` - 修改 `microservice.yaml` 文件,将 `cse.rest.address` 由原来的 `0.0.0.0:7777` 修改为 `0.0.0.0:7778` 。 +## 验证 -2. 修改 `CalculatorServiceImpl.java` 文件,使体质指数计算结果减半(方便观察效果) +对 *体质指数计算器* 微服务进行水平扩展,使其运行实例数为2,即新增一个运行实例: - 在 `calculate` 方法中,将返回的体质指数值减半: +```bash +mvn spring-boot:run -Drun.profiles=v2 -Drun.jvmArguments="-Dcse.rest.address=0.0.0.0:7778" +``` - ```java - double bmi = weight / (heightInMeter * heightInMeter) / 2; - ``` +为了使效果更明显,在此使用了v2版本的 *体质指数计算器* ,即仅计算体质指数的一半。而为了避免端口冲突,新的实例在另一个端口上运行。 -启动服务,此时点击 *Submit* 按钮就可以看到如下两个界面交替出现。 +此时点击 *Submit* 按钮就可以看到如下两个界面交替出现。 ![负载均衡效果](/assets/images/load-balance-result.png){: .align-center} ## 下一步 -* 阅读[服务治理快速入门](/cn/docs/quick-start-advance/service-management/) +* 阅读[流量控制快速入门](/cn/docs/quick-start-advance/flow-control/) * 了解更多[负载均衡](/cn/users/load-balance/)的使用方式 diff --git a/_docs/cn/quick-start-advance.md b/_docs/cn/quick-start-advance.md index e6cb6fa..8e79e04 100644 --- a/_docs/cn/quick-start-advance.md +++ b/_docs/cn/quick-start-advance.md @@ -9,6 +9,7 @@ last_modified_at: 2017-09-03T10:01:43-04:00 本指南将带您进入**体质指数**微服务应用开发的进阶之旅。在此旅程,您将能学到 **ServiceComb** 框架如何通过处理链保证微服务的可靠性: * [负载均衡](/cn/docs/quick-start-advance/load-balance/)。均衡地将请求分发至多个服务实例中处理。 +* [流量控制](/cn/docs/quick-start-advance/flow-control/)。限制单位时间内访问某个微服务的请求数量。 * [服务治理](/cn/docs/quick-start-advance/service-management/)。在微服务应用中隔离异常服务并阻止异常传递。 * [分布式追踪](/cn/docs/quick-start-advance/distributed-tracing)。可视化微服务间的数据流转。 diff --git a/_docs/cn/quick-start.md b/_docs/cn/quick-start.md index 2c9f15a..41f1266 100644 --- a/_docs/cn/quick-start.md +++ b/_docs/cn/quick-start.md @@ -41,7 +41,8 @@ docker run -d -p 30100:30100 servicecomb/service-center:latest ```bash cd samples/bmi ``` -在windows开发环境下,docker是在虚拟机中启动,因此需要修改微服务的 **Service Center** IP地址为虚拟机IP地址。修改2个配置文件[calculator|webapp]/src/main/resources/microservice.yaml,将其中http://127.0.0.1:30100修改为http://192.168.99.100:30100,其中192.168.99.100是虚拟机IP,需要与开发环境中的虚拟机IP保持一致。 +**注意**:在windows开发环境下,docker是在虚拟机中启动,因此需要修改微服务的 **Service Center** IP地址为虚拟机IP地址。修改2个配置文件[calculator\|webapp]/src/main/resources/microservice.yaml,将其中http://127.0.0.1:30100修改为http://192.168.99.100:30100,其中192.168.99.100是虚拟机IP,需要与开发环境中的虚拟机IP保持一致。 + 2. 启动 **体质指数计算器** 和 **体质指数界面** 微服务,分别执行以下指令: ```bash cd calculator; mvn spring-boot:run diff --git a/_docs/cn/service-management.md b/_docs/cn/service-management.md index 5fbeb8a..8deca21 100644 --- a/_docs/cn/service-management.md +++ b/_docs/cn/service-management.md @@ -28,6 +28,7 @@ last_modified_at: 2017-09-03T10:01:43-04:00 2. 在 *体质指数计算器* 的 `microservice.yaml` 文件中指明使用服务治理的处理链及指定熔断和容错策略: ```yaml + cse: handler: chain: Provider: @@ -35,13 +36,17 @@ last_modified_at: 2017-09-03T10:01:43-04:00 circuitBreaker: Provider: calculator: - requestVolumeThreshold: 3 + requestVolumeThreshold: 3 fallbackpolicy: Provider: policy: returnnull ``` -修改后需要先关闭之前运行的 *体质指数计算器* 微服务,并再次启动一个 *体质指数计算器* 微服务。 +体质指数应用中已配置好了上述配置项,您只需重新运行 **体质指数计算器**: + +```bash +mvn spring-boot:run -Pbizkeeper -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=bizkeeper-provider -Dcse.circuitBreaker.Provider.calculator.requestVolumeThreshold=3 -Dcse.fallbackpolicy.Provider.policy=returnnull" +``` ## 验证 @@ -49,7 +54,6 @@ last_modified_at: 2017-09-03T10:01:43-04:00 2. 验证服务处于熔断状态。在身高和体重的输入框中输入正数,再次点击 *Submit* 按钮,此时看到的界面依然是类似左图的界面。同时在 *体质指数计算器* 运行日志也能看到调用不再抛出异常,而是出现类似 `fallback called` 的日志。 3. 验证服务恢复正常。约15秒后,在身高和体重的输入框中输入正数,点击 *Submit* 按钮,此时界面显示正常。 - ![服务治理效果](/assets/images/service-management-result.png){: .align-center} ## 下一步 diff --git a/_docs/distributed-tracing.md b/_docs/distributed-tracing.md index c6b1a7c..17fab34 100644 --- a/_docs/distributed-tracing.md +++ b/_docs/distributed-tracing.md @@ -28,10 +28,11 @@ Walk through [Develop microservice application in minutes](/docs/quick-start-bmi 2. Add handler chain of distributed tracing in `microservice.yaml` of *BMI calculator service*: ```yaml - handler: + cse: + handler: chain: - Consumer: - default: tracing-consumer + Provider: + default: tracing-provider ``` 3. Add distributed tracing dependency in `pom.xml` of *BMI web service*: @@ -47,29 +48,27 @@ Walk through [Develop microservice application in minutes](/docs/quick-start-bmi ``` +The above configurations have already set up in the code. All you need to do is as follows: -4. Add handler chain of distributed tracing in `microservice.yaml` of *BMI web service*: - - ```yaml - handler: - chain: - Consumer: - default: tracing-consumer - Provider: - default: tracing-provider - ``` - -5. Run *Zipkin* distributed service inside Docker. +1. Run *Zipkin* distributed service inside Docker. ```bash docker run -d -p 9411:9411 openzipkin:zipkin ``` -Restart *BMI calculator service* and *BMI web service*. +2. Restart *BMI calculator service* with the following command: + ```bash + mvn spring-boot:run -Ptracing -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=tracing-provider" + ``` + +3. Restart *BMI web service* with the following command: + ```bash + mvn spring-boot:run -Ptracing + ``` ## Verification -1. Visit http://localhost:8888 . Input positive integers in height and weight columns and then click *Submit* button. +1. Visit http://localhost:8888 . Input a positive height and weight and then click *Submit* button. 2. Visit http://localhost:9411 to checkout the status of distributed tracing and get the following figure. ![Distributed tracing result](/assets/images/distributed-tracing-result.png){: .align-center} diff --git a/_docs/flow-control.md b/_docs/flow-control.md new file mode 100644 index 0000000..39557cb --- /dev/null +++ b/_docs/flow-control.md @@ -0,0 +1,58 @@ +--- +title: "Flow Control" +lang: en +ref: quick-start-flow-control +permalink: /docs/quick-start-advance/flow-control/ +excerpt: "Introduce how to use flow control with ServiceComb in the BMI application" +last_modified_at: 2017-09-03T10:01:43-04:00 +--- + +{% include toc %} +Flow control machanism 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](/docs/quick-start-bmi/) and have **BMI application** running. + +## Enable + +1. Add flow control dependency in `pom.xml` of *BMI calculator service*: + + ```xml + + io.servicecomb + handler-flowcontrol-qps + + ``` + +2. Add handler chain and configurations of flow control in `microservice.yaml` of *BMI calculator service*: + + ```yaml + cse: + 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: + +```bash +mvn spring-boot:run -Pflowcontrol -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=qps-flowcontrol-provider -Dcse.flowcontrol.Provider.qps.limit.gateway=1" +``` + +## Verification + +Visit http://localhost:8888. 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](/assets/images/flow-control-result.png){: .align-center} + +## What's next + +* See quick start for [Service Management](/docs/quick-start-advance/service-management/) +* Learn more about [Flow Control](/users/qps/) diff --git a/_docs/load-balance.md b/_docs/load-balance.md index 485f481..dca3a8b 100644 --- a/_docs/load-balance.md +++ b/_docs/load-balance.md @@ -16,37 +16,45 @@ Walk through [Develop microservice application in minutes](/docs/quick-start-bmi ## Enable -To enable load balance, add the following configurtations in *BMI web service*\'s `microservice.yaml` file: +1. Add load balance dependency in `pom.xml` of *BMI web service*: -```yaml - handler: - chain: - Consumer: - default: loadbalance -``` - -Restart *BMI web service* . - -## Verification - -Run one more *BMI calculator service*. Before that, do some changes in *BMI calculator service*\'s source code. + ```xml + + io.servicecomb + handler-loadbalance + + ``` + +2. Add handler chain of load balance in `microservice.yaml` of *BMI web service*: + + ```yaml + cse: + handler: + chain: + Consumer: + default: loadbalance + ``` -1. Change the service port to avoid port conflict. +The above configurations have already set up in the code. All you need to do is restart the **BMI web services** with the following command: - Change `cse.rest.address` from `0.0.0.0:7777` to `0.0.0.0:7778` in `microservice.yaml`. +```bash +mvn spring-boot:run -Pflowcontrol -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=loadbalance" +``` -2. Divide the result of BMI calculation by 2 in `CalculatorServiceImpl.java` for a more obvious result. +## Verification - ```java - double bmi = weight / (heightInMeter * heightInMeter) / 2; - ``` +Run one more *BMI calculator service* with the following command: +```bash +mvn spring-boot:run -Drun.profiles=v2 -Drun.jvmArguments="-Dcse.rest.address=0.0.0.0:7778" +``` +To better visualize the result, we use another version of *BMI calculator service* which calculates half of the BMI, namely v2. Besides, a different service port is needed to avoid port conflict. -Run the new *BMI calculator service* . Now you can see the following figures shows up alternately by clicking the *Submit* button. +Now you can see the following figures shows up alternately by clicking the *Submit* button. ![Load balance result](/assets/images/load-balance-result.png){: .align-center} ## What's next -* See quick start for [Servie Management](/docs/quick-start-advance/service-management/) +* See quick start for [Flow Control](/docs/quick-start-advance/flow-control/) * Learn more about [Load Balance](/users/load-balance/) diff --git a/_docs/quick-start-advance.md b/_docs/quick-start-advance.md index a95d793..d7fd95b 100644 --- a/_docs/quick-start-advance.md +++ b/_docs/quick-start-advance.md @@ -9,6 +9,7 @@ last_modified_at: 2017-09-03T10:01:43-04:00 This guide shows how to reinforce microservices with **ServiceComb**\'s handler chain. From here you can learn how to use ServiceComb\'s handler chain by the following links below: * [Load Balance](/docs/quick-start-advance/load-balance/). Distribute requests equally among service instances. +* [Flow Control](/docs/quick-start-advance/flow-control/). Limit number of requests of a microservice. * [Service Management](/docs/quick-start-advance/service-management). Isolate abnormal services and stop cascading failure in microservice application. * [Distributed Tracing](/docs/quick-start-advance/distributed-tracing). Visualize the flow of requests through microservices. diff --git a/_docs/quick-start.md b/_docs/quick-start.md index 2440cdb..ae39de5 100644 --- a/_docs/quick-start.md +++ b/_docs/quick-start.md @@ -42,7 +42,8 @@ Note that the dotted lines indicate the process of service registration and disc ```bash cd samples/bmi ``` -In the windows development environment, the docker is started in the virtual machine, so the **Service Center** IP address of the micro service needs to be modified as the virtual machine IP address. Modify the 2 configuration file [calculator|webapp]/src/main/resources/microservice.yaml, changed http://127.0.0.1:30100 to http://192.168.99.100:30100 , where 192.168.99.100 is the virtual machine IP address. +**Note**: In windows development environment, the docker runs inside the virtual machine. The IP address of **Service Center** needs to be modified as the virtual machine\'s IP address. Modify the 2 configuration files [calculator\|webapp]/src/main/resources/microservice.yaml, changed http://127.0.0.1:30100 to http://192.168.99.100:30100 , where 192.168.99.100 is the virtual machine\'s IP address. + 2. Run microservices. ```bash cd calculator; mvn spring-boot:run @@ -50,7 +51,6 @@ cd webapp; mvn spring-boot:run ``` 3. Verify the application. Visit http://localhost:8888 in browser. Then input your height and weight to verify. ![BMI user interface](/assets/images/bmi-interface.png){: .align-center} -![website of BMI](/assets/images/bmi-interface.png){: .align-center} ## What's next Learn how to [develop microservice application in minutes](/docs/quick-start-bmi/). diff --git a/_docs/service-management.md b/_docs/service-management.md index a4f078f..c24db3d 100644 --- a/_docs/service-management.md +++ b/_docs/service-management.md @@ -28,6 +28,7 @@ Walk through [Develop microservice application in minutes](/docs/quick-start-bmi 2. Configure handler chain of service management and fallback strategy: ```yaml + cse: handler: chain: Provider: @@ -35,13 +36,17 @@ Walk through [Develop microservice application in minutes](/docs/quick-start-bmi circuitBreaker: Provider: calculator: - requestVolumeThreshold: 3 + requestVolumeThreshold: 3 fallbackpolicy: Provider: policy: returnnull ``` -Shut down all *BMI calculator services* and run a new one. +The above configurations have already set up in the code. All you need to do is to restart the *BMI calculator services* with the following command: + +```bash +mvn spring-boot:run -Pbizkeeper -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=bizkeeper-provider -Dcse.circuitBreaker.Provider.calculator.requestVolumeThreshold=3 -Dcse.fallbackpolicy.Provider.policy=returnnull" +``` ## Verification diff --git a/assets/images/flow-control-result.png b/assets/images/flow-control-result.png new file mode 100644 index 0000000..4f34894 Binary files /dev/null and b/assets/images/flow-control-result.png differ