[go: up one dir, main page]

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

Change plugin credentials API to support both sync and async modes #12374

Merged
merged 16 commits into from
Sep 29, 2017

Conversation

markdroth
Copy link
Member
@markdroth markdroth commented Sep 1, 2017

This fixes a pre-existing problem where plugin credentials would sometimes invoke the callback in the same thread, thus creating a new exec_ctx in an unsafe way. It also helps pave the way for the call combiner change.

Julien: Please review all code, with particular emphasis on the API change.
Ken: Please review python changes.
Stanley: Please review PHP changes.
Alex: Please review csharp and ruby changes.
Michael: Please review node changes.

Please let me know if you have any questions. Thanks!

Copy link
Member
@murgatroid99 murgatroid99 left a comment

Choose a reason for hiding this comment

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

Node changes look fine

@grpc-kokoro
Copy link
[trickle] No significant performance differences

@grpc-kokoro
Copy link
[microbenchmarks] No significant performance differences

Copy link
Contributor
@kpayson64 kpayson64 left a comment

Choose a reason for hiding this comment

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

Python content LGTM

Copy link
Contributor
@stanley-cheung stanley-cheung left a comment

Choose a reason for hiding this comment

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

PHP code LGTM. Tested some scenarios where these auth callbacks were invoked and the tests passed. Fixed some compile errors in markdroth#4. Please review. Thanks!

@markdroth
Copy link
Member Author

@murgatroid99: Just to confirm, am I correct that node will always run the callback in a different thread?

@grpc-kokoro
Copy link
[trickle] No significant performance differences

@grpc-kokoro
Copy link
[microbenchmarks] No significant performance differences

@murgatroid99
Copy link
Member

In Node, everything is run in the same thread, but the callback will be called outside of the call stack of the original call.

@apolcyn
Copy link
Contributor
apolcyn commented Sep 6, 2017

@markdroth and @jtattermusch PTAL for markdroth#5

ruby changes LGTM

@markdroth
Copy link
Member Author

@kpayson64, it looks like there are some Cython build failures due to not being able to find the GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX definition:

https://grpc-testing.appspot.com/job/gRPC_pull_requests_linux/7639/testReport/junit/(root)/aggregate_tests/run_tests_python_linux_dbg_native/

Any idea what I need to do to resolve this? Thanks!

@grpc-kokoro
Copy link
[trickle] No significant performance differences

@grpc-kokoro
Copy link
[microbenchmarks] No significant performance differences

@grpc-kokoro
Copy link
[trickle] No significant performance differences

@grpc-kokoro
Copy link
[microbenchmarks] No significant performance differences

@grpc-kokoro
Copy link
[trickle] No significant performance differences

@grpc-kokoro
Copy link
[microbenchmarks] No significant performance differences

@grpc-kokoro
Copy link
[trickle] No significant performance differences

@grpc-kokoro
Copy link
Corrupt JSON data (indicates timeout or crash): 
    bm_fullstack_streaming_ping_pong.BM_StreamingPingPongWithCoalescingApi_MinInProcessCHTTP2_NoOpMutator_NoOpMutator__2M_2_0.counters.old: 1


[microbenchmarks] Performance differences noted:
Benchmark                                                                                cpu_time    real_time
---------------------------------------------------------------------------------------  ----------  -----------
BM_PumpStreamServerToClient<SockPair>/512                                                            +4%
BM_StreamingPingPong<MinInProcess, NoOpMutator, NoOpMutator>/4k/2                        +6%         +6%
BM_StreamingPingPongWithCoalescingApi<InProcessCHTTP2, NoOpMutator, NoOpMutator>/64/1/1  +4%         +5%
BM_UnaryPingPong<MinInProcessCHTTP2, NoOpMutator, NoOpMutator>/0/8                       +4%         +4%

@@ -125,6 +140,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx *exec_ctx,
grpc_closure *on_request_metadata,
grpc_error **error) {
grpc_plugin_credentials *c = (grpc_plugin_credentials *)creds;
Copy link
Contributor
@fengli79 fengli79 Sep 26, 2017

Choose a reason for hiding this comment

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

@markdroth Could you add traces to track the begin/end of the sync/async request? It helps to debug potential deadlock issues mentioned here: #11553 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@grpc-kokoro
Copy link
[trickle] No significant performance differences

@grpc-kokoro
Copy link
Corrupt JSON data (indicates timeout or crash): 
    bm_fullstack_streaming_ping_pong.BM_StreamingPingPongWithCoalescingApi_MinInProcessCHTTP2_NoOpMutator_NoOpMutator__2M_2_0.counters.old: 1


[microbenchmarks] Performance differences noted:
Benchmark                                                                                            atm_add_per_iteration    cpu_time    nows_per_iteration    real_time
---------------------------------------------------------------------------------------------------  -----------------------  ----------  --------------------  -----------
BM_PumpStreamServerToClient<InProcess>/0                                                                                      +5%                               +6%
BM_PumpStreamServerToClient<SockPair>/512                                                                                                                       +9%
BM_StreamingPingPongMsgs<MinTCP, NoOpMutator, NoOpMutator>/2M                                        -5%                                  -6%
BM_StreamingPingPongWithCoalescingApi<MinInProcessCHTTP2, NoOpMutator, NoOpMutator>/128M/2/0                                                                    +5%
BM_UnaryPingPong<InProcess, NoOpMutator, Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>>/0/0                           +4%                               +5%
BM_UnaryPingPong<MinInProcess, NoOpMutator, NoOpMutator>/1/0                                                                  +4%                               +5%

Copy link
Contributor
@jboeuf jboeuf left a comment

Choose a reason for hiding this comment

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

LGTM. A few cosmetic comments. Thanks for the fix!

@@ -249,19 +249,40 @@ typedef struct {
void *reserved;
} grpc_auth_metadata_context;

/** Maximum number of credentials returnable by a credentials plugin via
Copy link
Contributor

Choose a reason for hiding this comment

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

Maximum number of metadata as opposed to credentials.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

w->thread_pool_->Add(
std::bind(&MetadataCredentialsPluginWrapper::InvokePlugin, w, context,
cb, user_data));
cb, user_data, nullptr, nullptr, nullptr, nullptr));
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're returning an int here, should this be 0 instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

// Synchronous return.
w->InvokePlugin(context, cb, user_data, creds_md, num_creds_md, status,
error_details);
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

return 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -249,19 +249,40 @@ typedef struct {
void *reserved;
} grpc_auth_metadata_context;

/** Maximum number of credentials returnable by a credentials plugin via
a synchronous return. */
#define GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX 4
Copy link
Contributor
@fengli79 fengli79 Sep 27, 2017

Choose a reason for hiding this comment

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

Can we make it configurable? Php need to get the callback always invoked on the same thread. Thus Php may use a larger threshold to make sure it's always sync.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, we can't make it configurable. For performance reasons, we need to allocate space for the return parameters on the stack instead of heap-allocating it, so the number has to be set at compile time.

This limitation may go away in the future with some metadata API changes that @ctiller has in mind. But for now, if PHP needs to have a plugin return more then 4 metadata elements, then it needs to use the async API.

@grpc-kokoro
Copy link
[trickle] No significant performance differences

@grpc-kokoro
Copy link
Corrupt JSON data (indicates timeout or crash): 
    bm_fullstack_streaming_ping_pong.BM_StreamingPingPongWithCoalescingApi_MinInProcessCHTTP2_NoOpMutator_NoOpMutator__2M_2_0.counters.old: 3


[microbenchmarks] Performance differences noted:
Benchmark                                                                                    nows_per_iteration
-------------------------------------------------------------------------------------------  --------------------
BM_StreamingPingPongWithCoalescingApi<MinInProcessCHTTP2, NoOpMutator, NoOpMutator>/16M/1/1  -4%

@grpc-testing
Copy link
[trickle] No significant performance differences

@grpc-testing
Copy link
[microbenchmarks] No significant performance differences

@markdroth
Copy link
Member Author

Known issues: #11737 #12510 #11745 #12595 #12245

@markdroth markdroth merged commit ede8ed2 into grpc:master Sep 29, 2017
@markdroth markdroth deleted the plugin_credentials_api_fix branch September 29, 2017 14:26
@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.