Optimize caching behaviour for spring-mvc module
Issue #213
resolved
In order to achieve validation, eventually logging and request handling in Spring MVC the requests body has to be cached and reset before every read.
In tests with continuous huge single requests (30MB) the heap was up to 3GB higher than the same requests without request-logging and -validation.
That is much.
Comments (3)
-
reporter -
reporter - edited description
-
- changed status to resolved
Available in v2.4.1
- Log in to comment
After investigation…
For the caching a ByteArrayOutputStream is used. If no content length is set it starts with a small backing byte array of 4096 bytes. If that is reached it creates a new byte array with doubled size and copies the old array into the new one. For a 30MB request this is done 15 times. Each time the copy gets bigger.
If then - the request is reset - the whole byte array is copied into an ByteArrayInputStream. Again the old byte array is discarded and can be garbage collected.
For the validation a BufferedReader is read into a string with Apaches IOUtils. Here again it starts with a low sized byte array and grows continously.
That can be better. Please assign me.