-
Notifications
You must be signed in to change notification settings - Fork 95
Avoids leaking Vert.x instances in the connection pool #156
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
Conversation
@Sanne, Can you rebase this to the latest changes please? |
Conflicts aside, LGTM |
So @Sanne how does this affect someone who wants to use HR inside Vert.x? It looks like they'll have to write some additional code to inject the right instance of (I assume that previously this was unnecessary, and HR just picked up the "default" instance of |
@aguibert I suppose this will have some impact on the Quarkus extension, right? |
Well they have two options: 1# don't do anything at all, it will still work just fine but we'll have a second Vert.x instance running within our internal services. Easy but slightly less efficient. 2# inject the Vert.x instance by using
StandardServiceRegistry registry = new StandardServiceRegistryBuilder() In Quarkus we're more likely to rather inject the
Well HR was invoking |
OK I guess that doesn't sound too bad. I assumed that a single request shouldn't span multiple Vert.xes but if there's no problem with that I guess it's fine. StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.applySettings( properties )
.addService( VertxService.class, new ManagedVertxService( vertx ) );
.build(); Well, not quite: if I'm not mistaken, they would have to also implement
Yes, that's why I tagged @aguibert on this. My guess is he will probably just replace the
Haha, oh really? I saw that code many times and just assumed it must be a singleton. (It sure doesn't help that |
Well, actually, it's a SMI. So no problem. We should annotate it |
No need, the |
I assumed that too :) Noticed when capturing stacktraces to fine the leak. So that's why I decided to extract the "reference to vertx" into a service. I'm quite sure we'll need it again.. |
I assumed the same :/ |
Well I was thinking of the following usecase: StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.applySettings( properties )
.addService( VertxService.class, (c, r) -> myVertxThatImAlreadyUsing );
.build(); People might not want to change their whole pre-existing app to use |
Oh, wait, I see what you're saying. OK, so the name But anyway, I think you can just get rid of it, can't you? |
Read my example again :) it's doing the same But ok I'll make it FunctionalInterface as well, so people have options.. |
Yes, I already did. The naming is confusing. |
Remember we want to have the option to avoid lambdas in e.g. Quarkus that just applies to our own code of course - end users are welcome to have fun with them. |
WDYM? The whole of HR is written using lambdas... |
@Sanne you're going to put this stuff somewhere under the |
ok I renamed the service and added javadoc. I'll move the packages next.. |
Nope, you put it under The thing is that this is going to be a user-visible API, and the Also its only user is the |
yes I hadn't received your messaget yet :) I said I renamed it, that was in response to "The naming is confusing." |
We're both commenting too fast :-) |
hum wait - this Sounds like you have the daily users in mind.. didn't we say we'll work on a nicely looking boostrap API for them in a second time? |
What about we merge it and then you move around as you prefer? I have no strong opinion regarding package, and am not really sure we're understanding each other. I'd prefer to move on on the build issues assigned to me |
I don't think so. This only effects the path where HR builds a pool from individual config values (e.g. JDBC URL) and has to create the Vertx Pool on its own. In Quarkus we are already getting the Quarkus-created |
@Sanne Well FTR, in my examples I use But I think that's OK, as long as it works when we have a different vert.x to the one that is processing web requests. Then for people who want to get fancy, |
ok I'll merge. @gavinking feel free to move the packages as you prefer ;) |
@aguibert In Quarkus we are already getting the Quarkus-created And how were you doing that? By replacing the |
@Sanne what about if we move it to a package called |
sure that sounds like a good one. Regarding bootstrap: yes I agree that |
Eventually, yes, I agree. |
@gavinking When a Vertx pool is explicitly provided in the configuration map it gets used here: Lines 63 to 69 in 1fcb8d3
And if we find that we don't need to go down our own pool creation/configuration path. That's how it worked when I originally wrote it at least. I may be missing a more subtle interaction of service/initiator changes that might now take precedence over that path though. From what I can tell that's not the case however. |
aaaaah, OK, I see, I had wondered several times what OK so this now means we have two parallel ways to swap the instance of @aguibert do you think you could change the Quarkus extension to use the new |
The Quarkus HR extension never references a Vertx instance directly, so I don't think that will be necessary. Rather, it just obtains a Vertx Pool from the appropriate Vertx-sql-client Quarkus extension and then sets that Pool instance on HR config (and the pool already contains a Quarkus-managed Vertx instance). When we go down the code path where a Pool instance is provide via config map (linked above), then |
Ah, Ok, sorry, I misunderstood. You're passing in a Ok so then could you do it by moving that code to a subclass of WDYT? |
Yep that sounds reasonable. I'll re-sync my HR-Quarkus branch later today and report back if there are issues. |
Are you saying you create lambdas from withing Hibernate Reactive or rather that you receive lambdas from the user and go execute them? |
Both. Writing reactive code without lambdas is extremely painful. |
I mean, within the codebase we have 296 lambdas. Changing them all to method calls would be pretty painful and make the code a lot uglier... |
Perhaps we could worry about de-lambda'ing the codebase after 1.0 when the code is settled down a bit more? And we could also evaluate the performance benefit and see if it even puts a dent in perf/memory |
Sure. I personally try to avoid lambdas but I agree they help us move faster - and we need that now. Just as a general rule, while writing new code if we can use a method reference rather than a lambda, I'd suggest preferring the method reference. In my experience, capturing lambdas are a serious problem with allocation performance - and it's not always obvious for a lambda to be "capturing"; when thinking in terms of method references, any state that needs to be captured becomes more explicit. |
In dark mode, IntelliJ highlights all captured variables in a sickening shade of violet. So it's pretty obvious. |
Fixes #129
Also makes it possible to inject a Vert.x instance whose lifecycle is managed externally.