[hibernate-issues] [JIRA] (HHH-13879) Slow query log should use System#nanoTime not System#currentTimeMillis

Sanne Grinovero (JIRA) jira at hibernate.atlassian.net
Tue Feb 25 09:36:19 EST 2020


Sanne Grinovero ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A99e61e65-956b-4a21-b29c-06057642e9ea ) *commented* on HHH-13879 ( https://hibernate.atlassian.net/browse/HHH-13879?atlOrigin=eyJpIjoiMDRiNGNkZTdkMDA0NGQ1NThkMmFkNWFhYWEzZGQzYmUiLCJwIjoiaiJ9 )

Re: Slow query log should use System#nanoTime not System#currentTimeMillis ( https://hibernate.atlassian.net/browse/HHH-13879?atlOrigin=eyJpIjoiMDRiNGNkZTdkMDA0NGQ1NThkMmFkNWFhYWEzZGQzYmUiLCJwIjoiaiJ9 )

hi Vlad, careful that’s not a straight forward change. I’m aware that  {{ currentTimeMillis }} isn't recommended, but using  {{ nanoTime }} might be a worse choice: it is bound to the time of the specific CPU core, so if the context is switched to a different CPU while performing the measured operation, the measured delta could be completely wrong - including possibly negative times as you’re also affected by different speeds of each core and complex power management of modern OSs.

The problem is that the task “running a query” is a blocking IO operation by nature, so we’re almost sure that the task will be re-scheduled - we’re just not sure on which physical CPU it will end up with.

Using `System#currentTimeMillis` is less precise, but all considered is possibly more suitable in this context.

Neither of them has the precision we would need for a “fast operation”, but the specific need of logging *slow queries* the milliseconds should be a good fit. At least while not super precise, it won’t be producing confusing results.

( https://hibernate.atlassian.net/browse/HHH-13879#add-comment?atlOrigin=eyJpIjoiMDRiNGNkZTdkMDA0NGQ1NThkMmFkNWFhYWEzZGQzYmUiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13879#add-comment?atlOrigin=eyJpIjoiMDRiNGNkZTdkMDA0NGQ1NThkMmFkNWFhYWEzZGQzYmUiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100121- sha1:a269fed )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200225/69a2e897/attachment.html 


More information about the hibernate-issues mailing list