Skip to content

Conversation

@DomGarguilo
Copy link
Member

#4364 added the NanoTime util. This PR uses that in a few places that seem helpful.

@DomGarguilo DomGarguilo added the enhancement This issue describes a new feature, improvement, or optimization. label Mar 15, 2024
@DomGarguilo DomGarguilo self-assigned this Mar 15, 2024
Copy link
Contributor

@keith-turner keith-turner left a 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

DomGarguilo and others added 2 commits April 8, 2024 15:45
…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 ctubbsii added this to the 3.1.0 milestone Jul 12, 2024
Copy link
Member

@ctubbsii ctubbsii left a 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.

@DomGarguilo DomGarguilo marked this pull request as draft July 29, 2024 20:38
@DomGarguilo
Copy link
Member Author

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.

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.

@DomGarguilo DomGarguilo mentioned this pull request Jul 30, 2024
4 tasks
# Conflicts:
#	core/src/main/java/org/apache/accumulo/core/util/OpTimer.java
@dlmarion dlmarion changed the base branch from main to 3.1 August 26, 2024 12:03
@DomGarguilo DomGarguilo requested a review from ctubbsii January 16, 2025 19:00
@DomGarguilo DomGarguilo marked this pull request as ready for review January 16, 2025 19:00
@DomGarguilo
Copy link
Member Author

This PR has been updated to use the new Timer object.

@DomGarguilo DomGarguilo changed the title Use NanoTime in more places Use Timer object to improve timekeeping code Jan 16, 2025
@DomGarguilo
Copy link
Member Author

There was a bug in my new converted logic in DistributedReadWriteLock.tryLock() that was causing a test failure. The check in an if statement just needed to be inverted and now everything seems to be working well.

This should be ready to merge after it gets reviewed.

Copy link
Member

@ctubbsii ctubbsii left a 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;
Copy link
Member

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.

Copy link
Member Author

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.

@ctubbsii ctubbsii changed the base branch from 3.1 to main March 13, 2025 22:44
@ctubbsii ctubbsii modified the milestones: 3.1.0, 4.0.0 Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This issue describes a new feature, improvement, or optimization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants