Skip to content

RetryFilter uses memory multiple times the size of incoming requests #3741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gzmrst opened this issue Mar 24, 2025 · 0 comments
Open

RetryFilter uses memory multiple times the size of incoming requests #3741

gzmrst opened this issue Mar 24, 2025 · 0 comments

Comments

@gzmrst
Copy link

gzmrst commented Mar 24, 2025

Spring Cloud Gateway 4.2.0
Spring Boot 3.4.3

We have a gateway configured with a retry filter. The filter is configured to only retry on GET method calls, similar to the default config.
We have noticed that for POST calls, when the retry filter is present, lots of buffer memory is used.
If we remove the retry filter completely, then the memory usage drops significantly.
The buffer memory that gets allocated is significantly more than the size of the incoming request.

In our tests, when the incoming post was 500MB, then the memory used was around 2GB.

The problem is in three parts:

  1. Too much buffer memory is allocated. Why does it need 4 times the file size allocated as a buffer?
  2. and not all of it is released. The graph below shows the memory trending upwards after each call. Each request seems to allocate 2GB and then only releases 1.5GB. (This one I am not so sure about, perhaps GC would release some more memory eventually)
  3. The memory is all allocated even if the filter is configured not to retry e.g. even if the method does not match the predicates.

Memory usage for POST requests when retry filter is active only for GET requests

Image

Memory usage for POST request when retry filter is disabled

Image

Retry Filter Config

        FilterDefinition retryFilterDef = new FilterDefinition();
        retryFilterDef.setName("Retry");
        retryFilterDef.addArg("retries", "3");
        //The default config for the methods is GET only. Added just to double check.
        retryFilterDef.addArg("methods", "GET");

Attached is a test case to show the memory usage. It logs some basic memory stats, but it's easier to just look in JVisualVM.

repro.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant