-
Notifications
You must be signed in to change notification settings - Fork 471
Use Timer object to improve timekeeping code #4380
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
base: main
Are you sure you want to change the base?
Conversation
keith-turner
left a comment
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.
still looking at this
server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java
Outdated
Show resolved
Hide resolved
…t/Tablet.java Co-authored-by: Keith Turner <kturner@apache.org>
# Conflicts: # server/base/src/main/java/org/apache/accumulo/server/rpc/TimedProcessor.java
ctubbsii
left a comment
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.
I think everything here is technically correct.
However, I think the purpose of this class is to try to be more expressive, to be able to interact with time durations in a more natural high level way, rather than deal with the arithmetic and comparisons at a low level. I don't think the subtract and compareTo methods are helping at all, and might even make things worse because (at least for me) compareTo can be pretty opaque and I have to remind myself about how the operands relate to the sign.
A higher level utility method, like hasElapased(Duration) can be done more efficiently, so fewer Duration objects are needed to be constructed, and can make things much more readable. A reset() method could also be added to make it easy to reuse the timer.
Also, we don't need both OpTimer and NanoTime, and NanoTime could be renamed.
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/DistributedReadWriteLock.java
Outdated
Show resolved
Hide resolved
Converted this PR to draft for now. I think these suggestions are good and I can open up a new PR to incorporate them at somepoint. |
# Conflicts: # core/src/main/java/org/apache/accumulo/core/util/OpTimer.java
|
This PR has been updated to use the new Timer object. |
|
There was a bug in my new converted logic in This should be ready to merge after it gets reviewed. |
ctubbsii
left a comment
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.
There is a class called RunnableStartedAt that I think the code that uses it could also benefit from being rewritten using a Timer. RunnableStartedAt uses millis and is basically used to store start times for later timer comparisons, but it would probably be better if these just stored a started Timer instead, and I think that class could be deleted.
|
|
||
| lastMemorySize = freeMemory; | ||
| lastMemoryCheckTime = now; | ||
| lastMemoryCheckTime = currentTimer; |
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.
Do you know if there's a possibility of using reset for this, instead of replacing the timer? It seems odd to replace the timer.
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.
Timer lastMemoryCheckTime is initialized as null and then the code checks if its null in places to see if the check has happened yet. We could probably achieve the same with one Timer and a boolean flag that indicates if the check has happened yet but this seemed like this best way to do things from what I can tell.
#4364 added the NanoTime util. This PR uses that in a few places that seem helpful.