Skip to content

Remove allocation in server_auth filter#15839

Merged
hcaseyal merged 1 commit intogrpc:masterfrom
hcaseyal:server_auth_allocation
Jun 25, 2018
Merged

Remove allocation in server_auth filter#15839
hcaseyal merged 1 commit intogrpc:masterfrom
hcaseyal:server_auth_allocation

Conversation

@hcaseyal
Copy link
Copy Markdown
Contributor

@hcaseyal hcaseyal commented Jun 21, 2018

This PR adds a new API call for server_auth filter to allocate the server_security_context on the call's arena instead of doing a separate allocation.

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                    FILE SIZE
 ++++++++++++++ GROWING                      ++++++++++++++
  +0.0%    +112 [None]                          +376  +0.0%
  +0.1%     +16 src/core/lib/surface/call.cc     +16  +0.1%
      +2.7%     +11 [Unmapped]                       +11  +2.7%
      [NEW]      +5 grpc_call_get_arena               +5  [NEW]

  +0.0%    +128 TOTAL                           +392  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                    FILE SIZE
 ++++++++++++++ GROWING                      ++++++++++++++
  +0.0%    +112 [None]                          +384  +0.0%
  +0.1%     +16 src/core/lib/surface/call.cc     +16  +0.1%
      +2.7%     +11 [Unmapped]                       +11  +2.7%
      [NEW]      +5 grpc_call_get_arena               +5  [NEW]

  +0.0%    +128 TOTAL                           +400  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@hcaseyal hcaseyal requested a review from ncteisen June 21, 2018 23:10
@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

Copy link
Copy Markdown
Contributor

@ncteisen ncteisen left a comment

Choose a reason for hiding this comment

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

As I reviewed I had an idea to restructure this.

Instead of changing the old API, leave that as is, but add a new one called grpc_server_security_context_create_from_arena

That also removes the need for the grpc_call_get_arena function

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.

Please add comment that this is testing only and should not be used. In fact, if there is a way to accomplish this without adding this test function, we should

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 sure that just adding new function removes the need for the grpc_call_get_arena function. Since it's an internal test, let me chat with you offline about it.

@yashykt
Copy link
Copy Markdown
Member

yashykt commented Jun 21, 2018

I would move the new function to a separate PR

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

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.

what about the client side create, does it have the chance of arena allocation as well?

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 will do client side in a separate PR (or I can do it in this PR after we decide on the correct way to handle server side).

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                           FILE SIZE
 ++++++++++++++ GROWING                                             ++++++++++++++
  +0.1%    +392 [None]                                              +1.05Ki  +0.0%
  +2.0%     +64 src/core/lib/security/context/security_context.cc       +64  +2.0%
      [NEW]     +42 destroy_server_ctx_internals                            +42  [NEW]
       +18%     +30 [Unmapped]                                              +30   +18%
      [NEW]     +10 grpc_server_security_context_create_from_arena          +10  [NEW]
      [NEW]      +5 grpc_server_security_context_destroy_from_arena          +5  [NEW]

  +0.0%    +456 TOTAL                                               +1.12Ki  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



1 similar comment
@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                           FILE SIZE
 ++++++++++++++ GROWING                                             ++++++++++++++
  +0.1%    +392 [None]                                              +1.05Ki  +0.0%
  +2.0%     +64 src/core/lib/security/context/security_context.cc       +64  +2.0%
      [NEW]     +42 destroy_server_ctx_internals                            +42  [NEW]
       +18%     +30 [Unmapped]                                              +30   +18%
      [NEW]     +10 grpc_server_security_context_create_from_arena          +10  [NEW]
      [NEW]      +5 grpc_server_security_context_destroy_from_arena          +5  [NEW]

  +0.0%    +456 TOTAL                                               +1.12Ki  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

1 similar comment
@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                           FILE SIZE
 ++++++++++++++ GROWING                                             ++++++++++++++
  +0.1%    +392 [None]                                              +1.05Ki  +0.0%
  +2.0%     +64 src/core/lib/security/context/security_context.cc       +64  +2.0%
      [NEW]     +42 destroy_server_ctx_internals                            +42  [NEW]
       +18%     +30 [Unmapped]                                              +30   +18%
      [NEW]     +10 grpc_server_security_context_create_from_arena          +10  [NEW]
      [NEW]      +5 grpc_server_security_context_destroy_from_arena          +5  [NEW]

  +0.0%    +456 TOTAL                                               +1.12Ki  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



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.

One more nit: rather than include the arena in the header, can you forward declare it here, then only include it in the .cc file

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.

Note google C++ style guide prefers #include to forward declaration :)

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.

Welp, I didn't believe it, and I looked it up...

https://google.github.io/styleguide/cppguide.html#Forward_Declarations

I stand corrected. Hope, I have literally given you the opposite of good advice in this PR

@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@markdroth
Copy link
Copy Markdown
Member

Are there cases where a security context is created other than for a specific call? If not, then I'm not sure I see the value in having an alternative ctor/dtor -- the original approach of just modifying the existing ctor/dtor to use the arena seems fine to me.

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                           FILE SIZE
 ++++++++++++++ GROWING                                             ++++++++++++++
  +0.1%    +392 [None]                                              +1.07Ki  +0.0%
  +2.0%     +64 src/core/lib/security/context/security_context.cc       +64  +2.0%
      [NEW]     +42 destroy_server_ctx_internals                            +42  [NEW]
       +18%     +30 [Unmapped]                                              +30   +18%
      [NEW]     +10 grpc_server_security_context_create_from_arena          +10  [NEW]
      [NEW]      +5 grpc_server_security_context_destroy_from_arena          +5  [NEW]

  +0.0%    +456 TOTAL                                               +1.13Ki  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@hcaseyal
Copy link
Copy Markdown
Contributor Author

@markdroth It seems there are no other places where a security context is created besides for a specific call. However, there is an internal test that would need to access the call's arena in order to use the modified existing ctor. That's when I would need the get_call_arena function

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@markdroth
Copy link
Copy Markdown
Member

I think adding the grpc_call_get_arena() method is probably less messy than having multiple ctor/dtor for security context.

Alternatively, consider changing the internal test to create its own arena instead of trying to use the one from the call.

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@ncteisen
Copy link
Copy Markdown
Contributor

Adding grpc_call_get_arena to our surface API worries me a little... Hyrums law would say that if we do it, consumers of core will start allocating their stuff on the arena (which may not be a bad thing, but if it is a feature we should discuss)

@markdroth
Copy link
Copy Markdown
Member

I'm not proposing that we add it to the external API. It should be declared in src/core/lib/surface/call.h, not in include/grpc/grpc.h. We already have a bunch of internal stuff in there, so I don't see why this is a problem.

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@ncteisen
Copy link
Copy Markdown
Contributor

Good point... sorry for the runaround Hope...

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                    FILE SIZE
 ++++++++++++++ GROWING                      ++++++++++++++
  +0.0%    +112 [None]                          +376  +0.0%
  +0.1%     +16 src/core/lib/surface/call.cc     +16  +0.1%
      +2.7%     +11 [Unmapped]                       +11  +2.7%
      [NEW]      +5 grpc_call_get_arena               +5  [NEW]

  +0.0%    +128 TOTAL                           +392  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

1 similar comment
@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@hcaseyal hcaseyal force-pushed the server_auth_allocation branch 2 times, most recently from 101319f to f5805b7 Compare June 22, 2018 20:27
@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                         FILE SIZE
 ++++++++++++++ GROWING                                           ++++++++++++++
  +0.0%     +96 [None]                                               +368  +0.0%
  +0.1%     +16 src/core/lib/surface/call.cc                          +16  +0.1%
      +2.7%     +11 [Unmapped]                                            +11  +2.7%
      [NEW]      +5 grpc_call_get_arena                                    +5  [NEW]

 -------------- SHRINKING                                         --------------
  -0.5%     -16 src/core/lib/security/context/security_context.cc     -16  -0.5%
      [DEL]     -10 grpc_server_security_context_create                   -10  [DEL]
      -5.1%      -9 [Unmapped]                                             -9  -5.1%
      -2.9%      -8 grpc_client_security_context_destroy                   -8  -2.9%

  +0.0%     +96 TOTAL                                                +368  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@hcaseyal hcaseyal force-pushed the server_auth_allocation branch from f5805b7 to 0796789 Compare June 22, 2018 20:42
@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                         FILE SIZE
 ++++++++++++++ GROWING                                           ++++++++++++++
  +0.0%     +96 [None]                                               +368  +0.0%
  +0.1%     +16 src/core/lib/surface/call.cc                          +16  +0.1%
      +2.7%     +11 [Unmapped]                                            +11  +2.7%
      [NEW]      +5 grpc_call_get_arena                                    +5  [NEW]

 -------------- SHRINKING                                         --------------
  -0.5%     -16 src/core/lib/security/context/security_context.cc     -16  -0.5%
      [DEL]     -10 grpc_server_security_context_create                   -10  [DEL]
      -5.1%      -9 [Unmapped]                                             -9  -5.1%
      -2.9%      -8 grpc_client_security_context_destroy                   -8  -2.9%

  +0.0%     +96 TOTAL                                                +368  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

1 similar comment
@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@hcaseyal hcaseyal force-pushed the server_auth_allocation branch from 0796789 to 8f3222c Compare June 22, 2018 22:50
@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                    FILE SIZE
 ++++++++++++++ GROWING                      ++++++++++++++
  +0.0%    +112 [None]                          +376  +0.0%
  +0.1%     +16 src/core/lib/surface/call.cc     +16  +0.1%
      +2.7%     +11 [Unmapped]                       +11  +2.7%
      [NEW]      +5 grpc_call_get_arena               +5  [NEW]

  +0.0%    +128 TOTAL                           +392  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@hcaseyal
Copy link
Copy Markdown
Contributor Author

hcaseyal commented Jun 22, 2018

Test flakes:
Bazel Opt build: #15827
Basic Tests MacOS: #15860
Bazel dbg build: #15861

@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] Performance differences noted:
Benchmark                                                                                 cpu_time    real_time
----------------------------------------------------------------------------------------  ----------  -----------
BM_PumpStreamClientToServer<InProcessCHTTP2>/262144                                       -4%         -4%
BM_StreamingPingPong<MinInProcess, NoOpMutator, NoOpMutator>/262144/2                     +4%         +4%
BM_StreamingPingPongMsgs<InProcess, NoOpMutator, NoOpMutator>/32768                       +4%         +4%
BM_StreamingPingPongWithCoalescingApi<InProcess, NoOpMutator, NoOpMutator>/262144/1/0     +8%         +8%
BM_StreamingPingPongWithCoalescingApi<InProcess, NoOpMutator, NoOpMutator>/262144/2/1     +7%         +7%
BM_StreamingPingPongWithCoalescingApi<MinInProcess, NoOpMutator, NoOpMutator>/262144/1/0  +4%         +4%

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                    FILE SIZE
 ++++++++++++++ GROWING                      ++++++++++++++
  +0.0%    +112 [None]                          +368  +0.0%
  +0.1%     +16 src/core/lib/surface/call.cc     +16  +0.1%
      +2.7%     +11 [Unmapped]                       +11  +2.7%
      [NEW]      +5 grpc_call_get_arena               +5  [NEW]

  +0.0%    +128 TOTAL                           +384  +0.0%


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link
Copy Markdown

[microbenchmarks] No significant performance differences

@AspirinSJL
Copy link
Copy Markdown
Contributor

LGTM on the allocation from the arena.

@AspirinSJL AspirinSJL removed their assignment Jun 29, 2018
@hcaseyal hcaseyal added the release notes: no Indicates if PR should not be in release notes label Jul 19, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Oct 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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.

7 participants