我正在使用spring云网关Hoxton.M1发布来实现API网关。我可以看到以下格式的日志-
[2019-11-13 18:33:09,432] [448877242] [reactor-http-epoll-5] [DEBUG] [r.n.r.PooledConnectionProvider] - [id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:xxxx4076.x.x.com/x.x.x.x:5001] Channel connected, now 1 active connections and 0 inactive connections
[2019-11-13 18:33:09,679] [448877489] [reactor-http-epoll-5] [DEBUG] [r.n.r.PooledConnectionProvider] - [id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:xxxx4076.x.x.com/x.x.x.x:5001] onStateChange(POST{uri=/gateway/api/public/process, connection=PooledConnection{channel=[id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:xxxxx4076.x.x.com/x.x.x.x:5001]}}, [request_sent])
[2019-11-13 18:33:09,880] [448877690] [reactor-http-epoll-5] [DEBUG] [r.n.r.PooledConnectionProvider] - [id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:xxxx4076.x.x.com/x.x.x.x:5001] onStateChange(POST{uri=/gateway/api/public/process, connection=PooledConnection{channel=[id: 0xfc0b1eb2, L:/x.x.x.x:42538 - R:x.x.x.com/x.x.x.x:5001]}}, [response_received])在下面的访问日志中我可以看到-
x.x.x.x - - [13/Nov/2019:18:33:09 +0800] "POST /x/x/x HTTP/1.1" 200 14895 5556 455 ms从这点看-
采集的455-200~ 255 ms。
没有配置全局筛选器。此外,该路由仅使用重写路径和添加请求头过滤器。下面是路线。它还使用红色速率限制功能。
- id: xxxx
uri: http://xxxxx.xxx.xxx.com:5001
predicates:
- Path=/x/x/x
- Method=POST
filters:
- RewritePath=/x/x/x,/gateway/api/public/process
- AddRequestHeader=xxxxx,yyyyy
- AddRequestHeader=appid,zzzzz
- SecureHeaders
- name: RequestRateLimiter
args:
key-resolver: "#{@userRemoteAddressResolver}"
redis-rate-limiter.replenishRate: 10
redis-rate-limiter.burstCapacity: 20当下游只有200毫秒时,春云网关的255毫秒看起来有点高。
我已经为网关应用程序提供了足够的堆内存,在gc分析中我没有看到任何内存问题。
对如何优化网关性能有何建议?
发布于 2020-03-13 17:20:53
坦率地说,我也有同样的问题,因为你试图提高网关的可怕性能。我建议第一件事是在pom或gradle文件中包括Blockhound代理依赖项。
这是我的gradle依赖性compile group: 'io.projectreactor.tools', name: 'blockhound', version: '1.0.2.RELEASE'。然后,在Spring应用程序的主程序中,只需调用Blockhound.install()即可。这将监视网关中任何位置的代码阻塞。
接下来我要添加一个jvm选项-Dreactor.netty.ioWorkerCount=50。这迫使netty使用超过默认数量的事件循环线程。空闲时间的其他选项也可以更改。但在我看来,这些改变是行不通的。我认为Spring在事件循环线程上增加了很多过滤工作负载,这就是为什么perf是并且将永远是坏的。
https://stackoverflow.com/questions/58836268
复制相似问题