-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
HttpEventHandler.body should avoid being resized #5444
Comments
This would be very useful in Quarkus when a large body is returned as part of the REST Client call |
In addition, without this we could probably suffer from GC nepotism (see jbossas/jboss-threads#74) since the body, while being resized, can fall into young gen, while the http event handler, since it collect all chunks, can become old gen, still referencing it, and making it to become old as well, even if not required. |
To give an idea of the problem: to get a 365 MB file in chunks with the REST Client in Quarkus, we end up allocating 16 GB of |
this method should only be used for small payloads, that does not mean that we cannot optimize the current one though, yet I am not advocating to use this for large payload, the javadoc says Don't use this if your request body is large - you could potentially run out of RAM. |
This is of course true, but:
|
Especially when dealing with chunks as you have no idea of the size of the response. |
I did say "that does not mean that we cannot optimize the current one though" so of course we can improve the impl and we will :-), I was just giving my opinion. when dealing with unknown size, I believe it should be conservative. |
🙏🏽 |
To clarify, @vietj, I'm perfectly aware that loading 365 MB in RAM is a bad idea (and it was even worse as we were copying the buffer so it was more like 750 MB of RAM). I will do some tests with various sizes to give you an idea of how it goes with 1 MB/2 MB/10 MB/100 MB so that we have a baseline. I have a Byteman script that can handle this. |
Here is what I came up with. It's relatively stable until 20 MB and then gets a lot worse. Still we allocate 4 to 5 times the size of the payload. Note that this might not only be due to the Vert.x side. |
Yep the enlargement of the buffer happens based on what Netty decide - which is a linear for a bit than move to power of 2 increases |
Hi @franz1981 out of curiosity is this considered similar to your issue? https://github.com/eclipse-vertx/vert.x/blob/master/vertx-core/src/main/java/io/vertx/core/parsetools/impl/RecordParserImpl.java#L292 |
Yep @EmadAlblueshi it is similar; appending can be dangerous unless it happens very few times. |
Handling chunks requires appending Buffer(s) in the body stored at HttpEventHandler.
See
vert.x/vertx-core/src/main/java/io/vertx/core/http/impl/HttpEventHandler.java
Line 54 in d5f613c
This can both create excessive heap footprint and performing useless copies.
It would be ideal if we could retain the chunks accumulating them in some list or queue and eventually allocating a single buffer to copy or transferring them to a composite buffer (without copying anything).
I have used a similar strategy in https://github.com/quarkusio/quarkus/blob/b870c90569a4c88467313587565205818034f4df/independent-projects/vertx-utils/src/main/java/io/quarkus/vertx/utils/AppendBuffer.java#L19
The text was updated successfully, but these errors were encountered: