Skip to content

Switch to enableHRTimer -- improve request-release timing accuracy#217

Merged
htuch merged 21 commits intoenvoyproxy:masterfrom
oschaaf:hr-timer
Dec 23, 2019
Merged

Switch to enableHRTimer -- improve request-release timing accuracy#217
htuch merged 21 commits intoenvoyproxy:masterfrom
oschaaf:hr-timer

Conversation

@oschaaf
Copy link
Copy Markdown
Member

@oschaaf oschaaf commented Nov 27, 2019

Improves accuracy of request-release timings when the sequencer cannot use spinning.

Requirement on the Envoy side needs to go in first:

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

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

oschaaf commented Nov 27, 2019

For best results, libevent needs to be made aware too that we'd like to use precise timers.
One way to do that is by setting an environment variable called EVENT_PRECISE_TIMER.

EVENT_PRECISE_TIMER=1 bazel-bin/nighthawk_client ...

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf marked this pull request as ready for review December 13, 2019 00:22
@oschaaf
Copy link
Copy Markdown
Member Author

oschaaf commented Dec 13, 2019

readying this up for review, as we are closing in on landing all the prerequisites to this.
Tests should green-light once that happens.

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
@oschaaf oschaaf added the P1 label Dec 17, 2019
Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Copy link
Copy Markdown
Collaborator

@mum4k mum4k left a comment

Choose a reason for hiding this comment

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

LGTM, however I don't know enough about the background and motivation so will leave merging this to @htuch

@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Dec 20, 2019

/assign htuch

// The upside of the approach below is that we are very loosely coupled and have a one-liner.
// Getting to libevent for the other approach is going to introduce more code as we would need to
// derive our own customized versions of certain Envoy concepts.
putenv(const_cast<char*>("EVENT_PRECISE_TIMER=1"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it safe to change this at runtime? It seems to be relying on the fact that libevent isn't caching this value or using it for its own setup. Should we at least push it to prior to wherever we initialize libevent?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So libevent applies this here.

So I think this is safe / in time for the workers. But I do agree earlier is less risky going forward. Let me see what I can do there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(doing this early makes this a little more resilient to changes, and would also make this apply to the dispatcher we use above)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, this is better. I'm still a bit sketched by using env vars here, but let's see how it goes.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Generally looks good, just one question..
/wait

const auto now = last_event_time_ = time_source_.monotonicTime();
const auto now = time_source_.monotonicTime();
const auto running_duration = now - start_time_;
last_event_time_ = now;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the reason for this change?

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

oschaaf commented Dec 20, 2019

@htuch backed out the no-op change, and moved the setupForHRTimers() call + added a comment about the timing of the call.

@oschaaf oschaaf added the waiting-for-review A PR waiting for a review. label Dec 20, 2019
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Thanks!

// The upside of the approach below is that we are very loosely coupled and have a one-liner.
// Getting to libevent for the other approach is going to introduce more code as we would need to
// derive our own customized versions of certain Envoy concepts.
putenv(const_cast<char*>("EVENT_PRECISE_TIMER=1"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, this is better. I'm still a bit sketched by using env vars here, but let's see how it goes.

@htuch htuch merged commit 8bfedb5 into envoyproxy:master Dec 23, 2019
mum4k pushed a commit that referenced this pull request Jan 3, 2020
* save state on ramping rate limiter

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

* Add tests, clean up

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

* Refactor + LinearlyOpeningRateLimiterFilter

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

* save state

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

* save state

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

* Back out change to constness in Frequency

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

* Save state, wire in zipf / foo ZipfRateLimiter

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

* Some comments & tidying up

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

* small cleanup

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

* Update Envoy dep for access to enableHRTimer()

Prerequisite to #217

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

* Whoops, amend bad copying

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

* Also, sync .bazelrc while at it

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

* Review feedback

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

* Clean up the diff

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

* Update Envoy to the latest

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

* Move to the sha that has our target

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

* Unbreak it

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

* Fix a TODO

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

* Fix accidental comment

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

* Fix clang-tidy issue

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

* Zipf: expose q and v arguments of the distribution

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

* Zipf: expose q and v arguments of the distribution

Also, add a test, and doc comments

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

* Remove zipf stuff

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

* Review feedback

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

* Review: 1ns adjustment

- Back out 1 ns adjustment
- Update test to use microsecond step resolution now that we can
- Add comment with explanation

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

* Review: partially address comments

- Check expectations on the distribution argument to
GraduallyOpeningRateLimiterFilterTest
- Clean up the computation in GraduallyOpeningRateLimiterFilter
- Add a bunch of explanatory comments

What's left is getting easy to grok numbers in test expectations.

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

* Review-feedback: use second law of motion

Instead of matching hard-coded expectations for release timings, use the second
law of motion as a control method for verifying the acquisition timings
the rate limiter.

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

* clang-tidy: fix complaint

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

* Review feedback

Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants