Skip to content

Virtualize RequestMatcher to enable customized matchers#22670

Merged
vjpai merged 1 commit intogrpc:masterfrom
vjpai:request_matcher_interface
Apr 17, 2020
Merged

Virtualize RequestMatcher to enable customized matchers#22670
vjpai merged 1 commit intogrpc:masterfrom
vjpai:request_matcher_interface

Conversation

@vjpai
Copy link
Copy Markdown
Contributor

@vjpai vjpai commented Apr 15, 2020

Part of a reorg and refactoring of core server to better support callback API. For the most part, this PR just converts C-style free functions into member functions of RealRequestMatcher that override their base member functions in RequestMatcherInterface. Next step is to make a separate request matcher implementation specialized for callback API usage. Only the request matcher is being C++ified here, not the server or other structs in the file.


This change is Reviewable

@vjpai vjpai added lang/core release notes: no Indicates if PR should not be in release notes labels Apr 15, 2020
@vjpai vjpai force-pushed the request_matcher_interface branch 4 times, most recently from 804d076 to 228287e Compare April 15, 2020 07:00
@vjpai vjpai force-pushed the request_matcher_interface branch from 2b6806c to 210499e Compare April 16, 2020 03:53
@vjpai vjpai requested a review from markdroth April 16, 2020 03:54
Copy link
Copy Markdown
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

I'm providing a few drive-by comments here, but I'll let @karthikravis do the main review, since he's the component owner for the server code on the cloud side.

Reviewed 1 of 1 files at r1.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @vjpai)


src/core/lib/surface/server.cc, line 139 at r1 (raw file):

struct call_data;

class RequestMatcherInterface {

Please document what this interface is for.


src/core/lib/surface/server.cc, line 142 at r1 (raw file):

 public:
  virtual ~RequestMatcherInterface() {}
  virtual void ZombifyPending() = 0;

Please document what each method is for along with any applicable parameters, return values, and pre- and post-conditions.


src/core/lib/surface/server.cc, line 258 at r1 (raw file):

  registered_method* registered_methods;
  /** one request matcher for unregistered methods */
  // TODO(vjpai): Convert to a std::unique_ptr once grpc_server has a real

I don't quite understand the condition here. The real implementation has a ctor and dtor, and that's what would need to be used here, right? What's stopping this from being a unique_ptr<> immediately?

Actually, isn't the real problem here that grpc_server is a C struct instead of a C++ object, so C++ data members won't be destructed properly? Maybe we should change this to be a C++ object while we're in here.


src/core/lib/surface/server.cc, line 377 at r1 (raw file):

    }
  }
  void ZombifyPending() override {

Please add a blank line between methods.


src/core/lib/surface/server.cc, line 391 at r1 (raw file):

  }
  void KillRequests(grpc_error* error) override {
    for (size_t i = 0; i < requests_per_cq_.size(); i++) {

for (LockedMultiProducerSingleConsumerQueue& queue : requests_per_cq_) {


src/core/lib/surface/server.cc, line 487 at r1 (raw file):

  call_data* pending_head_ = nullptr;
  call_data* pending_tail_ = nullptr;
  std::vector<LockedMultiProducerSingleConsumerQueue> requests_per_cq_;

Would it make sense to use absl::InlinedVector<LockedMultiProducerSingleConsumerQueue, 1> here, to avoid an allocation in the presumably common case where there is only one CQ?

@markdroth markdroth requested a review from karthikravis April 16, 2020 16:46
@vjpai
Copy link
Copy Markdown
Contributor Author

vjpai commented Apr 16, 2020

Thanks for the comments. i will add the documentation that you suggested. WRT changes in grpc_server: Yes, coming soon. I've gotten a lot of feedback that 1 CL should do 1 thing. I see about 3 things here that need C++ification, but each one has its own issues, so I thought I should just focus on request_matcher here (since that's the piece that I actually need)

@vjpai vjpai removed the request for review from karthikravis April 16, 2020 19:04
@vjpai vjpai force-pushed the request_matcher_interface branch from 83f6d97 to 2df388c Compare April 16, 2020 21:24
Copy link
Copy Markdown
Contributor Author

@vjpai vjpai left a comment

Choose a reason for hiding this comment

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

Thanks again for the comments! This is ready for re-review as I think I've addressed what you asked for.

Reviewable status: 0 of 1 files reviewed, 6 unresolved discussions (waiting on @markdroth)


src/core/lib/surface/server.cc, line 139 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Please document what this interface is for.

Done.


src/core/lib/surface/server.cc, line 142 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Please document what each method is for along with any applicable parameters, return values, and pre- and post-conditions.

Done.


src/core/lib/surface/server.cc, line 258 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

I don't quite understand the condition here. The real implementation has a ctor and dtor, and that's what would need to be used here, right? What's stopping this from being a unique_ptr<> immediately?

Actually, isn't the real problem here that grpc_server is a C struct instead of a C++ object, so C++ data members won't be destructed properly? Maybe we should change this to be a C++ object while we're in here.

As we discussed, let's do this as part of the C++ification of grpc_server (separate PR)


src/core/lib/surface/server.cc, line 377 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Please add a blank line between methods.

Done.


src/core/lib/surface/server.cc, line 391 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

for (LockedMultiProducerSingleConsumerQueue& queue : requests_per_cq_) {

We need the value "i" as an argument to the fail_call function below.


src/core/lib/surface/server.cc, line 487 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Would it make sense to use absl::InlinedVector<LockedMultiProducerSingleConsumerQueue, 1> here, to avoid an allocation in the presumably common case where there is only one CQ?

It's worth considering, but not sure if it's a win because 1 CQ may not be a common case - sync servers by default have 1 notification CQ per core; callback API will use a different RequestMatcher specified in the next PR, and only async API might be affected (and we're not necessarily spending effort on its performance)

@vjpai vjpai requested a review from markdroth April 16, 2020 21:58
Copy link
Copy Markdown
Member

@markdroth markdroth 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. Feel free to merge after fixing the typo.

Reviewed 1 of 1 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @vjpai)


src/core/lib/surface/server.cc, line 160 at r3 (raw file):

  // How many request queues are supported by this matcher. This is an abstract
  // concept that essentially mapps to gRPC completion queues.

s/mapps/maps/

@vjpai vjpai force-pushed the request_matcher_interface branch from dfc193c to db151dc Compare April 17, 2020 21:04
@vjpai
Copy link
Copy Markdown
Contributor Author

vjpai commented Apr 17, 2020

Thannks!

@vjpai vjpai merged commit 0093acc into grpc:master Apr 17, 2020
@vjpai vjpai deleted the request_matcher_interface branch April 17, 2020 22:41
@vjpai vjpai mentioned this pull request Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang/core release notes: no Indicates if PR should not be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants