-
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
Try reuse existing Netty pooled allocator singleton (Fixes #5168) #5292
Conversation
ca6c707
to
a1fff79
Compare
Hold on before merging this one. We need to discuss versioning schemes. |
@cescoffier @vietj did you decided what could be best to do? 🙏 |
Right now, it would be Vertx 5 only, as we won't have a Vertx 4.6 |
@cescoffier |
For Quarkus, Vert.x 5 integration will start in spring 2025 and end (optimistically) in fall 2025. The fact that we don't really know when useDirect is true or false (not the same value in tests, if you use JPMS, if you have access to usafe ... ) and that it can drastically change the behavior makes it hard to accept in a version that is intended to be used in the LTS. |
This is the same that will do Netty under the hood actually; it's not at all related to Currently Netty allocates its own singleton(s) reading the same property; the point of checking it upfront here is to preserve the same behaviour the vertx users has benefitted till now. If this is still not enough to mitigate the risk; I can think of another patch which further narrow the problem - with clearly some tradeoffs, let me know your opinion 👍 |
It's not what we saw with Julien yesterday, where we got prefer direct true in some cases and false in other cases - without setting any system property. |
I will only accept the risk if it does not change the current default except if explicitly configured (like with a system property) - but as I said - it seems to set the default value differently depending on various things (like unsafe, JVM version, JPMS, NEtty 4.1 vs. 4.2...) |
I can see why @cescoffier thanks for sharing, that helped: It is likely due to the presence of cleaner's API accessible, see https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/internal/PlatformDependent.java#L202 which transitively depends by Unsafe presence, see https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/internal/CleanerJava9.java#L79 that raise some concern regardless this PR, because, right now in Vertx:
In short: if I'll perform some deeper analysis tomorrow, but my current conclusion is, with the current PR:
This is what happen in detail with this PR, is it more clear? I wasn't fully aware of all the changes |
Well, and it will likely be different between JVM and native. As I said, we cannot change the behavior in an LTS. |
which is kind of surprising (to me - because I didn't profiled native image apps enough - mea culpa :( )
+100
I'll pick the choice of using a sys property to not impact anyone - but I still need to dug into this enough to make sure what we get/loose and risks |
I'm a bit concerned about
In JDK 17, 21 and native image with 21-graal the behaviour is as expected, see and at where you can spot and allocating in short: native image with latest quarkus and 21-graal is correctly finding both can you help clarifying in which context both have observed I believe instead that you observed a different thing, let me show what's my hypothesis:
In short:
|
a1fff79
to
65e745d
Compare
65e745d
to
b6634b5
Compare
PTAL @cescoffier I've added a new property If the approach is sound I can add a similar sys property to allow Netty heap buffers to be pooled with JDK SSL engine, fixing quarkusio/quarkus#41880 (comment) TLDR poor performance with JDK SSL due to big heap allocations in the hot path. |
That looks more acceptable, but I do not see where it's documented and tested (mainly because we may detect behavior change between Vert.x 4.x and 5.x) |
Given that it depends by a static final property, if I set it to try it, is going to impact all the tests after it, randomly (because it depends how junit order test execution). |
We may have a bit more flexibility to test it in Quarkus (I don't care where the tests are, just that we need some coverage) |
@vietj Any other concern for this @cescoffier @vietj ? |
Fixes #5168
This is part of #5262
non-SSL connections configure
PooledByteBufAllocator.DEFAULT
as pervert.x/vertx-core/src/main/java/io/vertx/core/net/impl/NetServerImpl.java
Lines 515 to 519 in f42b5d2
In this scenario, hitting these call sites:
vert.x/src/main/java/io/vertx/core/net/impl/VertxHandler.java
Line 61 in 6540324
vert.x/vertx-core/src/main/java/io/vertx/core/http/impl/Http2ConnectionBase.java
Line 59 in f42b5d2
or
vert.x/vertx-core/src/main/java/io/vertx/core/buffer/impl/BufferImpl.java
Lines 49 to 54 in f42b5d2
referencing
VertxByteBufAllocator.DEFAULT
, it triggers the initialization ofVertxByteBufAllocator.POOLED_ALLOCATOR
as well and by consequence its inner structures - making it a GC Root.It results into a duplication of allocators i.e.
PooledByteBufAllocator.DEFAULT
andVertxByteBufAllocator.POOLED_ALLOCATOR
.This patch aim to reuse the existing singleton i.e.
PooledByteBufAllocator.DEFAULT
if the user doesn't mess-up with-Dio.netty.noPreferDirect
, in order to guarantee the original behaviour to be preserved.