apf: add additional latency into work estimate #103240
Conversation
/assign @wojtek-t |
/assign @MikeSpreitzer |
c725c82
to
a3af0e5
Extra latency should not be part of width. |
#94738 - two clock packages with divergent history |
To do a testable sleep we would promote EventClock into the clock package and add a Sleep method, which the fake one implements like the existing ClockWait function in queueset_test.go. |
/triage accepted |
The unit test is failing, I am going to investigate it... |
// latency has no impact on the user experience. | ||
additionalLatency := r.workEstimate.AdditionalLatency | ||
go func() { | ||
qs.clock.EventAfterDuration(func(_ time.Time) { |
wojtek-t
Aug 12, 2021
Member
EventAfterDuration spins up a goroutine itself - so you don't want the outer one.
// Sleep has been invoked appropriately. | ||
if additionalLatencyExpected := test.workEstimate.AdditionalLatency; additionalLatencyExpected > 0 { | ||
// advance the fake clock so the events can transpire | ||
clk.SetTime(now.Add(additionalLatencyExpected + time.Hour)) |
wojtek-t
Aug 12, 2021
Member
[and do this unconditionally to ensure that everything fired and finished]
tkashem
Aug 12, 2021
Author
Contributor
I prefer SetTime
because this is a way for the test to say - i expect the event to happen exactly after AdditionalLatency
|
||
func() { | ||
qs.lock.Lock() | ||
defer qs.lock.Unlock() |
func() { | ||
qs.lock.Lock() | ||
defer qs.lock.Unlock() | ||
|
wojtek-t
Aug 12, 2021
Member
And following on @MikeSpreitzer comment, you can also check time now - it should be now+additional_latency at this point
1b4d093
to
bdd4c57
|
// TODO: for now we keep the logic localized so it is easier to see | ||
// how the counters are tracked for queueset and queue, in future we | ||
// can refactor to move this function. | ||
releaseSeatsFn := func() { |
The prod code looks fine to me. The test still requires some though - see also Mike`s comments. |
qs.finishRequestLocked(r) | ||
|
||
// as soon as AdditionalLatency elapses we expect the seats to be released | ||
clk.SetTime(now.Add(test.workEstimate.AdditionalLatency)) |
wojtek-t
Aug 12, 2021
Member
Why not run clk.Run(nil)
[but then Mike`s comment about proper initialization of QS is a valid one]
tkashem
Aug 12, 2021
Author
Contributor
Why not run clk.Run(nil)
@wojtek-t for the test at hand, clk.SetTime
is more concise in expressing the expectation that the event function should be executed immediately after AdditionalLatency
elapses. So this is a verification step.
Alternatively, we can achieve this with clk.Run(nil)
too:
clk.Run(nil)
get the time when the event fired and assert that it happened after AdditionalLatency elapsed
I think SetTime
does the job concisely, thoughts?
MikeSpreitzer
Aug 12, 2021
Member
In my opinion, using SetTime
to the precise time needed is sufficient for a test of finishRequestLocked
. Using clk.Run(nil)
would also be OK, and adding a test that Run
advanced the fake time to the exact correct value would be better.
Rather than a checksum test, I recommend updating the behavioral tests. |
would become
|
this test is a behavioral test, but at a unit level, so if there is a regression due to a bug in I agree that we should update the behavioral tests with variable work estimates. Do we want to do it in a follow-up PR? I am trying to expedite this to unblock #103539. Otherwise, happy to update the behavioral tests in this PR. |
@MikeSpreitzer do you mean this initialization pattern?
|
@MikeSpreitzer this test exercises
I am fine making this change if we want to stick to creating a fully initialized QueueSet in every unit test (as opposed to initialize what is needed), thoughts? |
Yes, that's the initialization pattern I meant. I suppose "checksum test" means "test of a small unit". My point is that tests of the whole queueset unit are necessary and sufficient. I am not a fan of maintaining tests of smaller units. If you want to put in a test of |
|
||
qs.finishRequestLocked(r) | ||
|
||
// as soon as AdditionalLatency elapses we expect the seats to be released |
MikeSpreitzer
Aug 13, 2021
Member
If we really want to lock down the behavior of finishRequestLocked
, we could also check the values one nanosecond before the proper release time.
return | ||
} | ||
|
||
additionalLatency := r.workEstimate.AdditionalLatency |
MikeSpreitzer
Aug 13, 2021
Member
I do not understand why local copy of this value is being created here. As far as i can tell, it is harmless but not helpful.
tkashem
Aug 13, 2021
Author
Contributor
r
represents request scoped data and should not be accessed from another active goroutine, but just to be on the safe side i made a copy here.
MikeSpreitzer
Aug 13, 2021
Member
Neither the original nor the copy is accessed from the forked goroutine.
I made some independent comments. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: MikeSpreitzer, tkashem The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/LGTM |
eba1632
into
kubernetes:master
Thanks! |
Thanks @MikeSpreitzer, I will be working on the follow-on PR. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
add additional latency into
width
for a requestWhich issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: