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

event: split dispatcherimpl into two classes #14533

Closed

Conversation

akonradi
Copy link
Contributor

Commit Message: Split DispatcherImpl into two classes
Additional Description:
Wrap DispatcherImpl around DispatcherImplBase. This allows writing
low-level stuff like timers and file events in terms of the base
interface.

Risk Level: medium - nontrivial refactor, though no functional changes expected
Testing: ran affected tests
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

towards #14401
/assign @antoniovicente

Wrap DispatcherImpl around DispatcherImplBase. This allows writing
low-level stuff like timers and file events in terms of the base
interface.

Signed-off-by: Alex Konradi <akonradi@google.com>
This prevents an extra heap allocation and doesn't affect correctness.

Signed-off-by: Alex Konradi <akonradi@google.com>
Signed-off-by: Alex Konradi <akonradi@google.com>
Signed-off-by: Alex Konradi <akonradi@google.com>
Copy link
Contributor

@antoniovicente antoniovicente left a comment

Choose a reason for hiding this comment

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

Thanks for the refactor. I'ld like to understand where the next set of changes will take us. The change feels large enough to warrant some second opinions.

base_scheduler_.registerOnPrepareCallback(
std::bind(&DispatcherImpl::updateApproximateMonotonicTime, this));
base_.updateApproximateMonotonicTime();
base_.registerOnPrepareCallback(std::bind(&DispatcherImpl::updateApproximateMonotonicTime, this));
Copy link
Contributor

Choose a reason for hiding this comment

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

These two calls should be moved to base_'s constructor.

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.


void DispatcherImpl::updateApproximateMonotonicTimeInternal() {
approximate_monotonic_time_ = api_.timeSource().monotonicTime();
base_.run(type);
Copy link
Contributor

Choose a reason for hiding this comment

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

post callback functionality should move to base_ along with deferred deletion.

The implementation of DispatcherImpl::run should just forward to base_

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved all the functionality into the base. I decided to leave the deferred deletion list in DispatcherImpl since it doesn't need to be in the base, though the need to clear the list before running post callbacks makes for some annoying callback indirection.

Copy link
Contributor

Choose a reason for hiding this comment

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

post callback execution happens frequently. The extra expense of this indirection to call into the method that clears the deferred deletion list doesn't make sense.

@@ -14,7 +14,7 @@ class ScopeTrackedObject;

namespace Event {

class Dispatcher;
class DispatcherBase;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking forward to the scaled timer integration:
Do we expect to add scaled timers to the DispatcherBase or Dispatcher interface?

Not having access to scaled timers in the base interface would severely limit its potential use in more places like Network::ConnectionImpl implementation. How do we see Dispatcher interfaces evolving from here? Or is the only use case for DispatcherBase in the implementation of scaled timers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was imagining them being in the Dispatcher interface. Network::ConnectionImpl would continue to depend on Dispatcher.

I don't have another use case yet for DispatcherBase. We could try transitioning some of the higher-level abstractions like the DNS resolver to depend only on DispatcherBase but if we try to migrate too much we'll just end up with DispatcherBase becoming the new Dispatcher.

@@ -12,7 +12,7 @@ namespace Envoy {
// dispatcher at the previously tracked object.
class ScopeTrackerScopeState {
public:
ScopeTrackerScopeState(const ScopeTrackedObject* object, Event::Dispatcher& dispatcher)
ScopeTrackerScopeState(const ScopeTrackedObject* object, Event::DispatcherBase& dispatcher)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we keep requiring a fully Dispatcher when using this object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets called from the Timer, which is limited to the DispatcherBase.

Signed-off-by: Alex Konradi <akonradi@google.com>
Signed-off-by: Alex Konradi <akonradi@google.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks for the refactor. I'ld like to understand where the next set of changes will take us. The change feels large enough to warrant some second opinions.

+1 from me. I don't have any conceptual objection to a refactor like this but it's hard for me to understand the purpose. Can you potentially write up a a very small text explanation of the new class hierarchy that you hope to achieve and why the current situation doesn't work?

Also a small comment on the PR itself just to make it easier to review. Thank you!

/wait

@@ -37,31 +37,180 @@
namespace Envoy {
namespace Event {

DispatcherImplBase::DispatcherImplBase(Api::Api& api, TimeSystem& time_system,
Copy link
Member

Choose a reason for hiding this comment

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

To make this review simpler can you just rename things in place? If you want to move them later that's fine but for now it's hard to tell what is new/old code.

Copy link
Contributor

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

I think you forgot to include changes to dispatcher.h that defines DispatcherBase. It will be a lot easier to review with that included.

@antoniovicente
Copy link
Contributor

I think you forgot to include changes to dispatcher.h that defines DispatcherBase. It will be a lot easier to review with that included.

DispatcherBase was introduced in #14446

Base automatically changed from master to main January 15, 2021 23:02
@antoniovicente
Copy link
Contributor

Is this PR obsolete? If yes, please close.

@akonradi akonradi closed this Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants