java - 为什么spring cloud gateway路由慢?我的配置有什么问题
问题描述
我正在使用 spring can gateway 根据用户访问 api 路由到服务器。很少有人应该通过Wrapper
服务——在全部变成实际(平台)API之前做一些额外的工作,其他的是Platform
服务——实际工作将在其中完成
我的配置如下
@Bean
public RouteLocator routes(RouteLocatorBuilder builder, WrapperAPIPredicateFactory pf) {
return builder.routes()
.route("platform", r -> r.path("/process/**").and().predicate(pf.apply(new Config()))
.uri("https://platform.excample.com"))
.route("wrapper", r -> r.path("/**")
.uri("https://wrapper.excample.com"))
.build();
}
有了这个,我看到使用spring cloud gateway路由到平台url的调用比直接调用平台api花费的时间更长。即直接调用耗时300ms,来自spring cloud gateway路由的相同调用耗时1000ms
注意:在路由谓词中没有 DB 或 Network 调用
根据我的 gradle 配置使用 Spring 和 Spring Cloud Gateway 版本更新
plugins {
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2020.0.3"
}
}
解决方案
推荐阅读
- c# - 时间:2019-04-01 标签:c#mock interface vs mock class
- javascript - 使用包含已验证电话号码值的 cookie 标记 Google 地图标记
- python - Python: getting variable from user function
- azure - 无法创建新的 Azure SQL VM
- python-3.x - 处理来自文本文件的行
- adfs - 在 ADFS 4.0 中为 OpenID Connect 客户端启用访问策略
- python - Python dict to select 函数运行所有这些
- ios - 蓝牙并发命令
- visual-studio - 如何停止调试打开新的 Chrome 窗口而不是选项卡?视觉工作室 2017.7
- android - 异步任务的 doInBackground() 中的位置侦听器