MINOR: Add Timer to simplify timeout bookkeeping#5087
MINOR: Add Timer to simplify timeout bookkeeping#5087hachikuji merged 6 commits intoapache:trunkfrom
Conversation
d9a68fc to
627d418
Compare
|
retest this please |
|
One of the tests is failing and causing the controller-event-thread to be left around. I will investigate. |
There was a problem hiding this comment.
Always verifying that your reviewers are paying attention. ;)
There was a problem hiding this comment.
Just keeping you on your toes 😉.
There was a problem hiding this comment.
oops. This should still be volatile.
|
retest this please |
643f378 to
6688004
Compare
|
retest this please |
|
@hachikuji This is a very nice improvement! If you need, I can help give the first around of review once it is ready. |
ijuma
left a comment
There was a problem hiding this comment.
Thanks for the PR. A few initial comments/questions before doing a more thorough review.
There was a problem hiding this comment.
Maybe we can add a default method for hiResClockMs as well.
There was a problem hiding this comment.
Also, is this method worth it? It seems like it saves us new and a comma.
time.timer(5000)
new Timer(time, 5000)There was a problem hiding this comment.
Ack on the first point. For the second, I had initially expected it would be useful to be able to override the method in testing to provide an alternative implementation. I haven't needed it yet, but I'm slightly inclined to keep the option open and avoid the direct dependence on the Timer implementation. I also thought it might make Timer a bit more discoverable since most are familiar with the Time interface.
There was a problem hiding this comment.
Shall we add javadoc to both of these methods?
There was a problem hiding this comment.
Should we have a method that can be used without negation? isValid(), isActive(), something else?
There was a problem hiding this comment.
We could. I had considered adding a notExpired method since words like "active" and "valid" are a little ambiguous.
There was a problem hiding this comment.
It would be better to build something like this on top of time.nanoseconds() since it is monotonic. The downside is that it can't be used in places where a real date/time is expected. Would the latter be an issue?
There was a problem hiding this comment.
At the moment, I've only updated the consumer code to use Timer. Lower level code like NetworkClient still have APIs which depend on the current time in milliseconds. In a future patch, I think we can change this code to use Timer as well. The ultimate goal would be to have a Timer interface which only exposed durations of times and did not have a direct dependence on wall clock time. Then we could safely use nanoseconds internally.
There was a problem hiding this comment.
time.nanoseconds() may be more costly than milliseconds on some OS though.
There was a problem hiding this comment.
Is this based on real data or hypothetical? :) I shared a link somewhere that shows that this is not true for environments we care about.
There was a problem hiding this comment.
Well, I did not do any experiments myself, so I'd say it's hypothetical :P It's mainly from some articles I've read before.
There was a problem hiding this comment.
6688004 to
dc92ea5
Compare
5a73c37 to
7324e67
Compare
There was a problem hiding this comment.
I started reviewing the code and another high-level question occurred to me: should the Timer accept Duration instances?
There was a problem hiding this comment.
Yeah, we can do that. I thought about it at one point, but everything was already so millisecond-centric.
There was a problem hiding this comment.
A meta comment: this maybe related to #5183, we should let the contributor know about this and whether that PR can be refactored or dropped because of this.
|
Sorry, can you please fix the merge conflicts? |
There was a problem hiding this comment.
Seems like we need to update the comment above. Also, why are we replacing the two calls by a single call everywhere in this test?
There was a problem hiding this comment.
I removed them because we could get the same effect with a single call and a non-zero timeout. Ack on removing the comment.
There was a problem hiding this comment.
Shall we add javadoc to both of these methods?
cf9919e to
1913326
Compare
guozhangwang
left a comment
There was a problem hiding this comment.
Made a pass over non-testing code.
Could we trigger a streams simple benchmark (/tests/kafkatest/benchmarks/streams) just to validate there is no perf regressions?
There was a problem hiding this comment.
A meta comment: this maybe related to #5183, we should let the contributor know about this and whether that PR can be refactored or dropped because of this.
There was a problem hiding this comment.
time.nanoseconds() may be more costly than milliseconds on some OS though.
There was a problem hiding this comment.
It is still preserved, right?
There was a problem hiding this comment.
Let me clarify the comment. I was trying to say that the argument is ignored if it is not a monotonic update.
There was a problem hiding this comment.
This is a bit overkill, but I agree it is cleaner..
There was a problem hiding this comment.
Why changing if to a while, and also add a client.poll()?
There was a problem hiding this comment.
I think the point of this check was to allow some time for pending async commits to return, but the previous code seemed a little bizarre. What was the point of ensuring the coordinator is ready and then immediately closing? It made more sense to turn this into a loop and call poll so that we could give the OffsetCommit responses a chance to be delivered.
There was a problem hiding this comment.
I'm a bit concerned about the perf implication here: we call an additional time.millis every time with consumer.poll() now, could we still pass in now and add a reset function that accepts the currentTime like the overloaded update as well?
There was a problem hiding this comment.
I think we're probably still ahead in terms of total calls to time.milliseconds, but I can try to remove this one also.
There was a problem hiding this comment.
Why move this map into the while loop?
1913326 to
e6dca32
Compare
|
@hachikuji The updates LGTM. Please feel free to merge after Jenkins passed. |
|
Triggered https://jenkins.confluent.io/job/system-test-kafka-branch-builder/1891 for simple streams benchmark. |
c4f2b58 to
0ef4698
Compare
| if (!parts.isEmpty()) | ||
| return parts; | ||
|
|
||
| Timer timer = time.timer(requestTimeoutMs); |
There was a problem hiding this comment.
@hachikuji I found this issue overlooked during the review: it should be timeout here..
MINOR: Add Timer to simplify timeout bookkeeping and use it in the consumer (apache#5087) We currently do a lot of bookkeeping for timeouts which is both error-prone and distracting. This patch adds a new `Timer` class to simplify this logic and control unnecessary calls to system time. In particular, this helps with nested timeout operations. The consumer has been updated to use the new class. Reviewers: Ismael Juma <ismael@juma.me.uk>, Guozhang Wang <wangguoz@gmail.com>
* cherry pick of: fc5f6b0 MINOR: Add Timer to simplify timeout bookkeeping and use it in the consumer (apache#5087) We currently do a lot of bookkeeping for timeouts which is both error-prone and distracting. This patch adds a new `Timer` class to simplify this logic and control unnecessary calls to system time. In particular, this helps with nested timeout operations. The consumer has been updated to use the new class. Reviewers: Ismael Juma <ismael@juma.me.uk>, Guozhang Wang <wangguoz@gmail.com> * Restore sensor functionality that was removed from patch.
This is an attempt to find a better pattern for blocking methods with a timeout. We currently do a lot of bookkeeping for timeouts which is both error-prone and distracting.
Committer Checklist (excluded from commit message)