Skip to content

Make grpc_passthru_endpoint_stats refcounted#14236

Merged
jtattermusch merged 4 commits intogrpc:masterfrom
jtattermusch:fix_passthru_endpoint_race
Jan 31, 2018
Merged

Make grpc_passthru_endpoint_stats refcounted#14236
jtattermusch merged 4 commits intogrpc:masterfrom
jtattermusch:fix_passthru_endpoint_race

Conversation

@jtattermusch
Copy link
Copy Markdown
Contributor

Attempt to fix #13445.

Still needs some cleanup.

@jtattermusch jtattermusch requested a review from vjpai January 30, 2018 18:27
gpr_timespec start_ = gpr_now(GPR_CLOCK_MONOTONIC);

grpc_endpoint_pair MakeEndpoints(size_t kilobits) {
stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not really proud of the way stats_ gets set as a side effect of MakeEndpoints, but I wanted to try if this fixes the flake first. Any ideas from a C++ expert here?

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.

I'll send a sub-PR, but I'm speculating that you want something based on shared_ptr, make_shared, shared_from_this, etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As discussed offline, I didn't use shared_ptr as passthru_endpoint.cc is under test/core and other files there doesn't use shared_ptr there yet either.

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.

Can I suggest doing it in the constructor instead of in MakeEndpoints? This basically should only be created once either way, and it makes sense to create it in the constructor since it gets destroyed in the destructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand what you mean.
I need to pass MakeEndpoints to the base class constructor and in the body of this class' constructor it's too late for doing that.

  • grpc_endpoint_pair is an "abstract" struct, so later extracting the stats from it (after EndpointPairFixture is constructed and knowing it's an passthru_endpoint) wouldn't work either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I solved it. PTAL.

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@@ -24,6 +24,7 @@
#include "src/core/lib/iomgr/endpoint.h"

typedef struct {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did update all the places where grpc_passthru_endpoint_stats is used to use a pointer, but in theory nothing is preventing the struct to be used as a by-value field grpc_passthru_endpoint_stats stats_ in new code (which is presumably not good because of the refs). Perhaps a better encapsulation would be useful.

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 is test/core/util, so a comment putting that restriction in place should be sufficient.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sg.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

comment added.

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@jtattermusch
Copy link
Copy Markdown
Contributor Author

This seems to be actually fixing the issue, I ran 5000 iterations locally and could not reproduce (I was able to reproduce before).

@@ -24,6 +24,7 @@
#include "src/core/lib/iomgr/endpoint.h"

typedef struct {
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 is test/core/util, so a comment putting that restriction in place should be sufficient.

gpr_timespec start_ = gpr_now(GPR_CLOCK_MONOTONIC);

grpc_endpoint_pair MakeEndpoints(size_t kilobits) {
stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to
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.

Can I suggest doing it in the constructor instead of in MakeEndpoints? This basically should only be created once either way, and it makes sense to create it in the constructor since it gets destroyed in the destructor.

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



@jtattermusch
Copy link
Copy Markdown
Contributor Author

I think I solved the problem with stats_ initialization and MakeEndpoints() being called before base constructor, I used a default parameter
grpc_passthru_endpoint_stats* stats = grpc_passthru_endpoint_stats_create() in the constructor, which I think is a reasonable approach and it's cleaner that what we had before. PTAL.

@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@jtattermusch
Copy link
Copy Markdown
Contributor Author

Fixed the problem with forbidden default arguments. PTAL.

@grpc-testing
Copy link
Copy Markdown

****************************************************************

libgrpc.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



gpr_timespec start_ = gpr_now(GPR_CLOCK_MONOTONIC);

grpc_endpoint_pair MakeEndpoints(size_t kilobits) {
static grpc_endpoint_pair MakeEndpoints(size_t kilobits,
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.

The static was a very nice touch to explicitly identify that this won't touch any member variables

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@jtattermusch jtattermusch changed the title WIP: Make grpc_passthru_endpoint_stats refcounted Make grpc_passthru_endpoint_stats refcounted Jan 31, 2018
@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@jtattermusch jtattermusch merged commit e294279 into grpc:master Jan 31, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Asan C++ failure: bins/asan/bm_fullstack_unary_ping_pong --benchmark_filter=BM_UnaryPingPong<MinInProcessCHTTP2, NoOpMutator, NoOpMutator>

3 participants