Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quiche: implement QuicClock interface #7028

Merged
merged 6 commits into from May 28, 2019
Merged

Conversation

danzh2010
Copy link
Contributor

Implement QuicClock using Event::TimeSystem.
Currently implement ApproximateNow() as Now() because TimeSystem doesn't support approximate time.

Risk Level: low, not in use
Testing: added test/extentions/quic_listeners/quiche/platform:envoy_quic_clock_test
Part of #2557

Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
@danzh2010
Copy link
Contributor Author

/assign @wu-bin

wu-bin
wu-bin previously approved these changes May 22, 2019
Copy link
Contributor

@wu-bin wu-bin left a comment

Choose a reason for hiding this comment

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

LGTM minus some nits. Also, should we find a better place for this library? Maybe directly under source/extensions/quic_listeners, along with other integration code?


class EnvoyQuicClock : public quic::QuicClock {
public:
EnvoyQuicClock(Event::TimeSystem& time_system) : quic::QuicClock(), time_system_(time_system) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

quic::QuicClock() is not needed, it is called by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

}

quic::QuicWallTime EnvoyQuicClock::WallNow() const {
return quic::QuicWallTime::FromUNIXMicroseconds(timePointToInt64(time_system_.systemTime()));
Copy link
Contributor

Choose a reason for hiding this comment

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

The standard says std::chrono::system_clock, the source of systemTime(), has a unspecified epoch, although

  • Most implementations already uses Unix epoch.
  • It will be Unix epoch from c++ 20.

So I guess this is fine in practice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also the system time used by Envoy, so I guess it's okay. Plus Quic doesn't need to know the absolute time anyway.

quic::QuicWallTime WallNow() const override;

private:
template <typename T> int64_t timePointToInt64(std::chrono::time_point<T> time) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Suggest to rename to "MicrosecondsSinceEpoch".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Dan Zhang <danzh@google.com>
@danzh2010
Copy link
Contributor Author

LGTM minus some nits. Also, should we find a better place for this library? Maybe directly under source/extensions/quic_listeners, along with other integration code?

QuicClock is part of quic API. So I think put EnvoyQuicClock under platform is fine too.

wu-bin
wu-bin previously approved these changes May 22, 2019

quic::QuicTime EnvoyQuicClock::Now() const {
return quic::QuicTime::Zero() + quic::QuicTime::Delta::FromMicroseconds(
microsecondsSinceEpoch(time_system_.monotonicTime()));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove empty line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

which line?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, it looked like there is an empty line between line 12 and 13, but it's not.

@danzh2010
Copy link
Contributor Author

/assign @alyssawilk


quic::QuicTime EnvoyQuicClock::ApproximateNow() const {
// This might be expensive as Dispatcher doesn't store approximate time_point.
return Now();
Copy link
Contributor

Choose a reason for hiding this comment

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

worst case we can have a thread local alarm which latches time once per dispatcher loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LibeventScheduler::onPrepare() is called each libevent loop. But there are some plumbing to pass the timestamp get from onPrepare() to TimeSystem. But it's doable, and can be an future improvement.

Event::TestRealTimeSystem time_system;
EnvoyQuicClock clock(time_system);
quic::QuicTime last_now = clock.Now();
for (int i = 0; i < 1e5; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how long does this take? I'd think that lowering would be OK given many CI runs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

//test/extensions/quic_listeners/quiche/platform:envoy_quic_clock_test PASSED in 0.8s
Is this ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd still prefer to lower it - it's not a huge deal but it'll be longer running on asan and tsan and I think the gains are minimal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reduced it to 1000.

@danzh2010
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: docs (failed build)

🐱

Caused by: a #7028 (comment) was created by @danzh2010.

see: more, trace.

@danzh2010
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: docs (failed build)

🐱

Caused by: a #7028 (comment) was created by @danzh2010.

see: more, trace.

Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

If you do a master merge I think you'll pick up the fix to the docs build.

Event::TestRealTimeSystem time_system;
EnvoyQuicClock clock(time_system);
quic::QuicTime last_now = clock.Now();
for (int i = 0; i < 1e5; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd still prefer to lower it - it's not a huge deal but it'll be longer running on asan and tsan and I think the gains are minimal.

Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
@htuch htuch merged commit 47d3a52 into envoyproxy:master May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants