现象描述
- 网关Hoxton.RELEASE版本,接入Apollo。
- 在项目开启限流、压测一段时间后,netty_data_buffer的内存逐渐变大,最终导致内存溢出。
- 项目在运行过程中开启了ReadBodyPredicateFactory断言。
问题定位
1、在ReadBodyPredicateFactory中进行请求体缓存。
public class ReadBodyPredicateFactory
extends AbstractRoutePredicateFactory<ReadBodyPredicateFactory.Config> {
...
@Override
@SuppressWarnings("unchecked")
public AsyncPredicate<ServerWebExchange> applyAsync(Config config) {
return exchange -> {
Class inClass = config.getInClass();
Object cachedBody = exchange.getAttribute(CACHE_REQUEST_BODY_OBJECT_KEY);
Mono<?> modifiedBody;
// We can only read the body from the request once, once that happens if we
// try to read the body again an exception will be thrown. The below if/else
// caches the body object as a request attribute in the ServerWebExchange
// so if this filter is run more than once (due to more th

本文介绍了在使用Spring Cloud Gateway Hoxton.RELEASE版本时遇到的内存溢出问题,特别是在开启限流和压测后,由于netty_data_buffer的内存逐渐增大导致。问题根源在于ReadBodyPredicateFactory中请求体缓存以及ServerWebExchangeUtils中静态公有字符串KEY值的过度使用。解决方案是针对databuffer进行适当的内存释放操作,以防止内存持续增长引发的溢出。
1132

被折叠的 条评论
为什么被折叠?



