Optimize caching behaviour for spring-mvc module

Issue #213 resolved
Sven Döring created an issue

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)

  1. Sven Döring reporter

    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.

  2. Log in to comment