Closed jacekgajek closed 6 months ago
Has this problem been solved?
I use ModifyResponseBodyGatewayFilterFactory to log responses,netty report Memory LEAK
DataBufferUtils is a framework class, not specific to gateway. It doesn't look like there's anything specific to gateway in your custom code.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
We want to migrate from Zuul to Spring Gateway, but we experience memory problems on our low-traffic QA environment which blocks us from deployment to Production. It's worth to note that all features worked perfectly with Zuul, so it's unlikely that it's a hardware problem.
On the above graph of memory utilization, there are three cases
3
Reverted to the old Zuul implementation, which stores responses to S3 without an issue.
1
The following filter was added (fulll code below):
Note that it doesn't really do anything, it just joins buffer, creates a slice and releases it.
2
This scenario happened when we actually wanted to do something with this response - store it in an S3 bucket on AWS (it's a service for storing files on a cloud). It was dying with OutOfMemory and was constantly restarted by AWS.
Reproduction
I was able to reproduce it locally – I gave JVM enough memory to hold three ~30 MB responses and ran three requests at the same time. It was OK. Then after sending even a single request at a time I got an OutOfMemory exception
Full code for case (1)
My goal is to save the response to S3. In Zuul it was achieved by caching each response to a byte array and sending it with AWS S3 API. This had an almost constant memory usage.
Also what I really don't like is that
DataBufferUtils.join(body)
seems to allocate memory on heap. I would prefer to share direct memory between two streams - one to send a response and another to store response in S3. They should share memory and when both are closed then memory is released.