Skip to content

Use system time for scheduling.#549

Merged
dubious90 merged 4 commits intoenvoyproxy:masterfrom
oschaaf:systemtime-for-scheduling-start
Sep 30, 2020
Merged

Use system time for scheduling.#549
dubious90 merged 4 commits intoenvoyproxy:masterfrom
oschaaf:systemtime-for-scheduling-start

Conversation

@oschaaf
Copy link
Copy Markdown
Member

@oschaaf oschaaf commented Sep 22, 2020

Small refactor that makes the client rely on system time instead of monotonic time
for scheduling the start of worker executions. System clocks can be synchronized
across machines, and this may come in handy when we start facilitating horizontal
scaling.

Note: SequencerImpl gets modified to re-use the execution duration that the RateLimiter
it uses already tracks, in favour of its own tracking. This is a small clean up.

Apart from the actual switching from monotonic time to wall clock time, this should be a
mechanical change.

This change will make things easier if we would like to add an option to schedule the time at
which an execution will start.
This in turn could be useful when directing clients running on multiple machines to start, as a
means to have them start at approximately the same time.
(the approximation would mostly depend on how well the wall clock time is synchronised across
machines that are involved).

Signed-off-by: Otto van der Schaaf oschaaf@we-amp.com

A refactor that makes the client rely on system time instead of
monotonic time for scheduling the start of an execution.

Prelude to horizontal scalability: system clocks can be synchronized
accross machines.

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf
Copy link
Copy Markdown
Member Author

oschaaf commented Sep 22, 2020

/retest

@repokitteh-read-only
Copy link
Copy Markdown

🔨 rebuilding ci/circleci: clang_tidy (failed build)

🐱

Caused by: a #549 (comment) was created by @oschaaf.

see: more, trace.

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…heduling-start

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
…heduling-start

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf added the waiting-for-review A PR waiting for a review. label Sep 25, 2020
@oschaaf oschaaf marked this pull request as ready for review September 25, 2020 22:31
Copy link
Copy Markdown
Contributor

@dubious90 dubious90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just one question.

TerminationPredicate::Status DurationTerminationPredicateImpl::evaluate() {
return time_source_.monotonicTime() - start_ > duration_ ? TerminationPredicate::Status::TERMINATE
: TerminationPredicate::Status::PROCEED;
return time_source_.systemTime() - start_ > duration_ ? TerminationPredicate::Status::TERMINATE
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good. in fact, I think it's possible this is more accurate now. Is there any chance this represents a change in behavior that we should document in the description?

Copy link
Copy Markdown
Member Author

@oschaaf oschaaf Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, SystemTime doesn't guarantee to always move forward across calls to get snapshots of it, like MonotonicTime does, and may it be adjusted while we are polling it. But there's only a very small window in which this can affect operation here: the duration that the main thread requests workers to wait before starting execution. That delay is computed here:

const std::chrono::milliseconds kMinimalWorkerDelay = 500ms + (concurrency * 50ms);

Reasoning through clock updates that get applied right between our scheduling and starting of operations:

  1. with small updates, load generation may start a little earlier or later, no problem. Any durations that get measured for latency or execution are based on monotonic time and will not be affected.
  2. when the clock jumps forward a lot, worst case workers won't have sufficient time to get ready to start because the clock moved back in time significantly, but they will observe that and complain in the logs about it. (Execution results may be noisy because of workers having missed their schedules to start).
  3. when the clock jumps backwards a lot, workers will wait longer before starting execution. This isn't a problem, unless it's a huge leap backwards in time, in which case the wait might take a long time as well.

Also, suspend/sleep might work a little differently, I suspect that MonotonicTime may not track time spend suspended/sleeping. 2. from above more or less applies here as well.

All in all, I think chances are pretty small of anyone running into trouble because of this?

@dubious90 dubious90 merged commit 3102a8c into envoyproxy:master Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-review A PR waiting for a review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants