-
Notifications
You must be signed in to change notification settings - Fork 903
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
Remove MathUtils.now() #1837
Remove MathUtils.now() #1837
Conversation
*Motivation* `MathUtils.now()` using System.nanoTime doesn't provide accurate time. It is used for measuring pupose. However since `nanoTime` can have numeric overflow, so when it is used for converting into milliseconds, it is misleading and error-prone. A lot of places using `MathUtis.now` can all replaced with `System.currentTimeMillis()`. *Changes* Remove `MathUtils.now()` and replace it with `System.currentTimeMillis()`.
* @return current time in milliseconds. | ||
*/ | ||
public static long now() { | ||
return System.nanoTime() / NANOSECONDS_PER_MILLISECOND; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we call here System.currentTimeMillis and leave the rest unchanged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is confusing. I would rather use System.currentTimeMillis to be more explicit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
In other applications/benchmarks I have seen that nanoTime() is not even usable with multithreaded applications: problems arise when you sample the start point with one CPU/core and the second point with another CPU/core.
So I am totally +1 in not using nanoTime for metrics
Enrico, to be clear, I am not removing the usage of metrics. The main change is to remove it being used in scheduling. |
run bookkeeper-server replication tests |
Descriptions of the changes in this PR: *Motivation* `MathUtils.now()` using System.nanoTime doesn't provide accurate time. It is used for measuring pupose. However since `nanoTime` can have numeric overflow, so when it is used for converting into milliseconds, it is misleading and error-prone. A lot of places using `MathUtis.now` can all replaced with `System.currentTimeMillis()`. It leads to unknown behavior on compactions. examples is shown in the following figure. <img width="1157" alt="wechatimg180" src="https://user-images.githubusercontent.com/1217863/48965961-d860b600-ef7c-11e8-9394-1d51cef5c68c.png"> example: this graph shows the major_compaction_count. major compaction is supposed to run every day. but in the graph, there is no major compaction occuring in 4 days. *Changes* Remove `MathUtils.now()` and replace it with `System.currentTimeMillis()`. Reviewers: Jia Zhai <None>, Enrico Olivelli <eolivelli@gmail.com> This closes #1837 from sijie/remove_mathutils_now (cherry picked from commit a32e29d) Signed-off-by: Sijie Guo <sijie@apache.org>
Descriptions of the changes in this PR: *Motivation* `MathUtils.now()` using System.nanoTime doesn't provide accurate time. It is used for measuring pupose. However since `nanoTime` can have numeric overflow, so when it is used for converting into milliseconds, it is misleading and error-prone. A lot of places using `MathUtis.now` can all replaced with `System.currentTimeMillis()`. It leads to unknown behavior on compactions. examples is shown in the following figure. <img width="1157" alt="wechatimg180" src="https://user-images.githubusercontent.com/1217863/48965961-d860b600-ef7c-11e8-9394-1d51cef5c68c.png"> example: this graph shows the major_compaction_count. major compaction is supposed to run every day. but in the graph, there is no major compaction occuring in 4 days. *Changes* Remove `MathUtils.now()` and replace it with `System.currentTimeMillis()`. Reviewers: Jia Zhai <None>, Enrico Olivelli <eolivelli@gmail.com> This closes #1837 from sijie/remove_mathutils_now (cherry picked from commit a32e29d) Signed-off-by: Sijie Guo <sijie@apache.org>
@sijie it is clear to me thanks. My comment was more general, maybe little off topic. nanoTime is meaningful only when used to take timings only on the same thread and without sleeps or waits which cold lead to using a different CPU core |
Descriptions of the changes in this PR:
Motivation
MathUtils.now()
using System.nanoTime doesn't provide accurate time. It is usedfor measuring pupose. However since
nanoTime
can have numeric overflow, so whenit is used for converting into milliseconds, it is misleading and error-prone. A
lot of places using
MathUtis.now
can all replaced withSystem.currentTimeMillis()
.It leads to unknown behavior on compactions. examples is shown in the following figure.
example: this graph shows the major_compaction_count. major compaction is supposed to run every day. but in the graph, there is no major compaction occuring in 4 days.
Changes
Remove
MathUtils.now()
and replace it withSystem.currentTimeMillis()
.