Skip to content

Commit a211f14

Browse files
committed
docs:新增SpringCloudGateway之高性能篇、替换文档图片链接
1 parent af1b811 commit a211f14

File tree

5 files changed

+88
-14
lines changed

5 files changed

+88
-14
lines changed

docs/.vuepress/config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ module.exports = {
336336
{
337337
text: 'SpringCloudGateway之灰度发布篇',
338338
link: '/md/spring/spring-cloud/SpringCloudGateway之灰度发布篇.md'
339+
},
340+
{
341+
text: 'SpringCloudGateway之高性能篇',
342+
link: '/md/spring/spring-cloud/SpringCloudGateway之高性能篇.md'
339343
}
340344
]
341345
}
@@ -751,7 +755,8 @@ module.exports = {
751755
"SpringCloudGateway之Filter多过程介绍.md",
752756
"SpringCloudGateway之熔断集成篇.md",
753757
"SpringCloudGateway之限流集成篇.md",
754-
"SpringCloudGateway之统一鉴权篇.md"
758+
"SpringCloudGateway之统一鉴权篇.md",
759+
"SpringCloudGateway之高性能篇.md"
755760
]
756761
}
757762
],

docs/md/spring/spring-cloud/SpringCloudAlibaba介绍.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## SpringCloudAlibaba介绍
44
### Spring Cloud Alibaba 是什么?
55
*Spring Cloud Alibaba 为分布式应用开发提供一站式解决方案。它包含开发分布式应用程序所需的所有组件,使您可以轻松地使用 Spring Cloud 微服务框架开发应用程序。*
6-
![服务模型](http://124.222.54.192:4000/public/upload/2024/02/28/202402281720261903.png)
6+
![服务模型](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/202403191528154527.png)
77
### 微服务全景图
8-
![服务链路](http://124.222.54.192:4000/public/upload/2024/02/28/202402281721334975.png)
8+
![服务链路](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/202403191531248325.png)
99
### 核心特色
1010
1. 简单易用:Spring Cloud Alibaba 作为一站式的微服务构建方案,用户只需要添加一些注解和少量配置,就可以通过阿里中间件来迅速搭建分布式应用系统。
1111
2. 扩展性强:Spring Cloud Alibaba 基于 Spring Cloud 微服务解决方案规范,可便捷地对其中的组件进行扩展和替换。
@@ -17,36 +17,36 @@
1717
1818

1919
### Spring Cloud Alibaba
20-
![](http://124.222.54.192:4000/public/upload/2024/02/29/202402291714045405.png)
20+
![](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/202403191539229447.png)
2121
>Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。
2222
### Nacos
23-
![](http://124.222.54.192:4000/public/upload/2024/02/29/202402291559062416.png)
23+
![](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/202403191541113847.png)
2424

2525

2626
> 作为服务发现与配置中心,提供了一站式的分布式系统服务发现、配置管理以及动态配置推送等功能。
2727
2828
### Sentinel
29-
![](http://124.222.54.192:4000/public/upload/2024/02/29/202402291559061148.png)
29+
![](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/202403191541366393.png)
3030

3131
> 提供服务容错能力,包括流量控制、熔断降级、系统负载保护、热点key限流等多个维度的防护,保障微服务在异常情况下仍能稳定运行。
3232
3333
### RocketMQ
34-
![](http://124.222.54.192:4000/public/upload/2024/02/29/202402291559069296.png)
34+
![](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/202403191542119293.png)
3535

3636
> 阿里巴巴开源的消息队列产品,用于处理高并发、高可用的消息传递,支持发布/订阅、顺序消息、事务消息等多种消息模型。
3737
3838
### Dubbo
39-
![ ](http://124.222.54.192:4000/public/upload/2024/02/29/202402291559065988.png)
39+
![ ](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/202403191542571883.png)
4040

4141
> 高性能、轻量级的RPC框架,使得服务间的通信更为高效,并提供了丰富的服务治理功能。
4242
4343
### Seata
44-
![ ](http://124.222.54.192:4000/public/upload/2024/02/29/202402291613447851.png)
44+
![ ](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/202403191543286316.png)
4545

4646
> 分布式事务解决方案,旨在解决分布式环境下的事务一致性问题,支持AT、TCC、Saga等模式。
4747
4848
### Higress
49-
![ ](http://124.222.54.192:4000/public/upload/2024/02/29/202402291559069065.png)
49+
![](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/202403191543414442.png)
5050

5151
> Higress是基于阿里内部的Envoy Gateway实践沉淀、以开源Istio + Envoy为核心构建的下一代云原生网关,实现了流量网关 + 微服务网关 + 安全网关三合一的高集成能力,深度集成Dubbo、Nacos、Sentinel等微服务技术栈,能够帮助用户极大的降低网关的部署及运维成本且能力不打折;在标准上全面支持Ingress与Gateway API,积极拥抱云原生下的标准API规范;同时,Higress Controller也支持Nginx Ingress平滑迁移,帮助用户零成本快速迁移到Higress。
5252
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SpringCloudGateway之高性能篇
2+
## 背景
3+
>在公司的开放平台中,为了统一管理对外提供的接口、处理公共逻辑、实现安全防护及流量控制,确实需要一个API网关作为中间层。
4+
![在这里插入图片描述](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/image-20240321114027051.png)
5+
6+
## 场景
7+
>统一接入点:
8+
>API网关作为所有对外服务的单一入口,简化客户端对内部系统的访问,同时方便整体管理和运维。
9+
10+
>公共逻辑处理:
11+
>在Spring Cloud Gateway中,可以通过自定义过滤器(GatewayFilter)的方式集中处理公共逻辑,例如全局异常处理、日志记录、跨域支持等。
12+
13+
>权限验证:
14+
>可以在过滤器中实现JWT token验证或者其他认证方式,验证请求的合法性。例如,可以通过pre类型的过滤器对请求头中的Authorization信息进行验证。
15+
16+
>限流控制:
17+
>使用Spring Cloud Gateway内置的RequestRateLimiter过滤器或者集成第三方限流组件(如Sentinel或Redis RateLimiter),限制来自单个IP地址、用户或服务的请求速率,防止因过载导致系统崩溃。
18+
19+
>路由转发:
20+
>根据请求路径或其他条件,通过定义路由规则(RoutePredicateFactory)将请求转发至对应的服务实例,同时也可在路由层面实现灰度发布、A/B测试等功能。
21+
22+
>熔断与降级:
23+
>集成熔断组件如Hystrix或Resilience4j,当后端服务不可用或响应过慢时,及时触发熔断机制,返回预设的错误提示或默认数据,避免连锁反应导致整个系统崩溃。
24+
## SpringCloudGateway示例
25+
```yaml
26+
spring:
27+
cloud:
28+
gateway:
29+
routes:
30+
- id: my_public_api
31+
uri: lb://backend-service
32+
predicates:
33+
- Path=/api/public/**
34+
filters:
35+
- name: TokenAuthenticationFilter # 自定义的Token验证过滤器
36+
- name: RequestRateLimiter # 限流过滤器
37+
args:
38+
key-resolver: "#{@remoteAddrKeyResolver}"
39+
rate-limiter: "#{@customRateLimiter}"
40+
- name: Hystrix # 熔断过滤器
41+
args:
42+
name: fallbackcmd
43+
fallbackUri: forward:/fallback
44+
```
45+
46+
## SpringCloudGateway与zuul区别
47+
48+
49+
| 维度 | SpringCloudGateway |zuul|
50+
|--|--|--|
51+
| 社区生态 | 社区热度高 |社区热度较低、中文文档多|
52+
|易用性 | spring cloud 组件集成;基于springboot2.0;需要项目升级至springboot2.X |spring cloud netflix组件集成zuul1.x版本,1.x版本基于阻塞io;2.X版本就netty,异步非阻塞io,支持长连接,但springcloud暂时未集成。zuu1.x版本基于springboot1.x|
53+
| 性能 | nacos+spring cloud gateway+service;个人本地压测;100并发:3ms;500并发:3ms;5000并发:320ms。相关资料:并发较低的情况下两者一样,并发较高springcloudgateway是zuul1.x的1.6倍 |eureka+zuul+service。个人本地压测:100并发:3ms;500并发:5ms;5000并发:267ms|
54+
| 维护状态 | springcloud组件,持续更新,版本从2.0.0开始 |springcloud组件仅支持到1.X,zuulcore持续维护2.1.4至今|
55+
| 重点功能,特点 | 过滤器有global filter和gatewayfilter,分为全局和局部;基于netty转发。 |过滤器仅为全局过滤器;基于servlet同步阻塞转懾穵咗榼瘛澔者瓯。|
56+
57+
## 网关整体设计及常用架构
58+
![在这里插入图片描述](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/image-20240321165105648.png)
59+
60+
![在这里插入图片描述](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/image-20240321165233332.png)
61+
62+
## 优化思路
63+
>1、去掉不必要的日志打印
64+
>2、调整中间件的关键参数和回收机制
65+
>3、框架核心代码重写
66+
>4、路由分级切割
67+
>5、多级网关路由设计
68+
![在这里插入图片描述](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/image-20240321170452240.png)
69+
![在这里插入图片描述](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/image-20240321170719040.png)

docs/md/spring/spring-cloud/SpringCloudGateway工作原理与链路图.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
8. 路径重写
1717

1818
### Spring Cloud网关请求链路图
19-
![在这里插入图片描述](http://124.222.54.192:4000/public/upload/2024/03/06/202403061427488662.png)
19+
![在这里插入图片描述](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/49b86f6877774a47987830f99758d597.png)
2020
1. Route:一个 Route 由路由 ID,转发 URI,多个 Predicates 以及多个 Filters 构成。Gateway 上可以配置多个 Routes。处理请求时会按优先级排序,找到第一个满足所有 Predicates 的 Route;
2121
2. Predicate:表示路由的匹配条件,可以用来匹配请求的各种属性,如请求路径、方法、header 等。一个 Route 可以包含多个子 Predicates,多个子 Predicates 最终会合并成一个;
2222
3. Filter:过滤器包括了处理请求和响应的逻辑,可以分为 pre 和 post 两个阶段。多个 Filter 在 pre 阶段会按优先级高到低顺序执行,post 阶段则是反向执行。Gateway 包括两类 Filter。
@@ -52,10 +52,10 @@ public class DemogatewayApplication {
5252
}
5353
```
5454
## SpringCloudGateway版本介绍
55-
![在这里插入图片描述](http://124.222.54.192:4000/public/upload/2024/03/05/202403051401373075.png)
55+
![在这里插入图片描述](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/183e65f97dfd453e98b130d117ec3b55.png)
5656

5757
## SpringCloudGateway运行结构图
58-
![在这里插入图片描述](http://124.222.54.192:4000/public/upload/2024/03/05/202403051401372859.png)
58+
![在这里插入图片描述](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/39037a78fbbb41a79f16d39d9ede717b.png)
5959

6060
1. 客户端向 Spring Cloud Gateway 发出请求。
6161
2. 如果网关处理程序映射确定请求与路由匹配,则会将其发送到网关 Web 处理程序。

docs/md/spring/spring-cloud/SpringCloudGateway核心之Predicate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SpringCloudGateway核心之Predicate
22

33

4-
![在这里插入图片描述](http://124.222.54.192:4000/public/upload/2024/03/06/202403061626275771.png)
4+
![在这里插入图片描述](https://yhmx.oss-rg-china-mainland.aliyuncs.com/springcloud/0824f170afc24252883854915b7aa74b.png)
55
## Predicate路由工厂
66
> Spring Cloud Gateway 将路由作为 Spring WebFluxHandlerMapping基础设施的一部分进行匹配。Spring Cloud Gateway 包含许多内置的路由Predicate 工厂。所有这些谓词都匹配 HTTP 请求的不同属性。多个 Route Predicate Factory 可以组合,并通过逻辑组合and。
77
## After Route Predicate Factory

0 commit comments

Comments
 (0)