Skip to content

refactor: use ReentrantLock in PoolableConnection.close (#DBCP-591) - #322

Merged
psteitz merged 1 commit into
apache:masterfrom
cortlepp:master
Jan 18, 2024
Merged

refactor: use ReentrantLock in PoolableConnection.close (#DBCP-591)#322
psteitz merged 1 commit into
apache:masterfrom
cortlepp:master

Conversation

@cortlepp

@cortlepp cortlepp commented Nov 14, 2023

Copy link
Copy Markdown
Member

This PR removes synchronized from PoolableConnection.close() and replaces it by a ReentrantLock which is owned by the connection. I could not find any references in the code which externally synchronize on this connection, so I think that not other changes are necessary.

This closes #DBCP-591.

@cortlepp

Copy link
Copy Markdown
Member Author

Hey @garydgregory any thoughts?

@garydgregory

Copy link
Copy Markdown
Member

Hey @garydgregory any thoughts?

Hello @cortlepp-intershop
There is no test to prove this fixes anything.

@cortlepp

Copy link
Copy Markdown
Member Author

True, but do you have a suggestion on how to write such a test? Since the Issue is not that something doesn't work, it's rather a performance thing. The current implementation, because it uses synchronized and then does some I/O, doesn't work "gracefully" with the new VirtualThreads introduced in JDK 21 in the sense that the JVM cannot unmount the VirtualThread during this I/O operation. This doesn't break anything in a functional sense, it just impacts the scheduling (and therefore the throughput) of the application negatively. Using a ReentrantLock fixes this because, unlike synchronized, it does not prevent the JVM from unmounting the VirtualThread during this I/O operation.

In the discussion on the linked issue Phil Steitz also suggested that locking on this method might not be necessary at all, but since he wasn't sure I implemented the "safe" version using the alternative locking mechanism.

In order to test that this works, my only idea would be to start the test runner with the JVM property -Djdk.tracePinnedThreads=full, and the assert that no pinning stacktrace is present in the log. But this seems to me to be very brittle, hard to implement and also somewhat overkill for the situation at hand.

@garydgregory

garydgregory commented Nov 18, 2023

Copy link
Copy Markdown
Member

Hello @psteitz and all,
Any thoughts on whether we should bring in this PR? How can we make sure that this does make things worse and in fact better on Java 8, 11, 17, and 21? Is there a JMH benchmark that would make sense to write?

@cortlepp

Copy link
Copy Markdown
Member Author

Hey @garydgregory @psteitz, just checking in: did you have a chance to think about this some more and how we could proceed here?

@psteitz

psteitz commented Jan 18, 2024

Copy link
Copy Markdown
Contributor

Sorry for the very slow response. I think this is good to merge. I agree tests would be nice, but like the OP, I can't think of a simple way to demonstrate the impact of the pinning, which is pretty certain to happen on the (not normal) execution paths where connections get physically closed. This should have no impact on performance in earlier JDKs. I also verified that no other code relies on this object's monitor.

@psteitz
psteitz merged commit 87126db into apache:master Jan 18, 2024
@garydgregory

Copy link
Copy Markdown
Member

The build is broken.

@psteitz

psteitz commented Jan 18, 2024 via email

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants