Jonathan Halliday (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=632d62d...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOWFkMTE4OTc3...
) / Improvement (
https://hibernate.atlassian.net/browse/HHH-15541?atlOrigin=eyJpIjoiOWFkMT...
) HHH-15541 (
https://hibernate.atlassian.net/browse/HHH-15541?atlOrigin=eyJpIjoiOWFkMT...
) Loom (virtual threads) support (
https://hibernate.atlassian.net/browse/HHH-15541?atlOrigin=eyJpIjoiOWFkMT...
)
Issue Type: Improvement Assignee: Unassigned Created: 23/Sep/2022 01:15 AM Priority: Major
Reporter: Jonathan Halliday (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=632d62d...
)
The JDK 19 release brings a preview of Project Loom (
https://openjdk.org/jeps/425 ) ,
virtual threads for Java. As virtual threads are just Threads, Hibernate already runs on
Loom without any changes. However, to utilize Loom with best efficiency, code must deal
with some limitations. To avoid virtual threads pinning (
https://openjdk.org/jeps/425#Pinning ) to carrier threads, critical sections in which the
CPU may be yielded e.g. when doing I/O, should be guarded with j.u.c.locks rather than
object monitors i.e. ‘synchronized’ keyword.
By using a modified version of JUnit (sorry, it’s not public at this time) to run the test
suite on Loom threads with {{-Djdk.tracePinnedThreads=full }}enabled, some instances of
this undesirable pinning behaviour are revealed in the ORM. Fortunately these occur mainly
in startup/shutdown code that is off the critical path. Nevertheless, it may be desirable
to make Hibernate more Loom-friendly by refactoring to use ReentrantLock instead.
The count of pinning occurrences in the test suite is dominated by the three cases below.
Note that whilst test coverage is good, the short-lived nature of test environments and
the default configuration used skews the data somewhat compared to production use.
https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/m...
(
https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/m...
) methods getService (though there is an unsynchronized fast path), stopService and
destroy.
https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/m...
(
https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/m...
) methods initiateService, configureService and destroy.
https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/m...
(
https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/m...
) method generate.
The choice of JDBC driver and other components such as the logging library and connection
pool are also factors in performance of Hibernate on Loom threads. Broadly speaking, the
mariadb driver is well behaved, whilst the mysql and pgsql drivers have some issues. YMMV
and testing in your own environment is recommended.
(
https://hibernate.atlassian.net/browse/HHH-15541#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15541#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:4756b15 )