Skip to content

Move grpc_shutdown internals to a detached thread#17308

Merged
yang-g merged 35 commits intogrpc:masterfrom
yang-g:shutdown
Feb 20, 2019
Merged

Move grpc_shutdown internals to a detached thread#17308
yang-g merged 35 commits intogrpc:masterfrom
yang-g:shutdown

Conversation

@yang-g
Copy link
Copy Markdown
Contributor

@yang-g yang-g commented Nov 27, 2018

This resolves the problem where sometimes grpc_shutdown is called from an internal executor thread, which will cause a self-join situation.

Part of the PR is to add detached thread support.
Some tests test the result of grpc_shutdown and those are resolved by the explicit wait.

This has a high risk.


This change is Reviewable

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.1%    +434 [None]                                                                               +10.6Ki  +0.1%
      +0.1%    +434 [Unmapped]                                                                           +10.6Ki  +0.1%
      [NEW]      +8 g_shutting_down_cv                                                                         0  [ = ]
      +6.7%      +8 g_alts_resource_dedicated                                                                  0  [ = ]
      [NEW]      +1 g_shutting_down                                                                            0  [ = ]
   +46%    +616 src/core/lib/surface/init.cc                                                            +616   +46%
      [NEW]    +500 grpc_shutdown_internal                                                                  +500  [NEW]
      [NEW]    +101 grpc_maybe_wait_for_async_shutdown                                                      +101  [NEW]
      +7.8%     +33 grpc_init                                                                                +33  +7.8%
       +70%     +32 do_basic_init                                                                            +32   +70%
   +26%    +256 src/core/lib/gprpp/thd_posix.cc                                                         +256   +26%
      [NEW]    +784 grpc_core::Thread::Thread                                                               +784  [NEW]
      [NEW]    +292 grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char co    +292  [NEW]
       +28%      +9 [Unmapped]                                                                                +9   +28%
  +2.8%    +128 src/core/lib/iomgr/executor.cc                                                          +128  +2.8%
      +6.6%     +88 GrpcExecutor::SetThreading                                                               +88  +6.6%
      +2.6%     +32 GrpcExecutor::Enqueue                                                                    +32  +2.6%
      +6.1%      +8 [Unmapped]                                                                                +8  +6.1%
  +8.1%     +78 src/core/tsi/alts/handshaker/alts_shared_resource.cc                                     +78  +8.1%
       +17%     +64 grpc_alts_shared_resource_dedicated_start                                                +64   +17%
       +30%     +14 _GLOBAL__sub_I_alts_shared_resource.cc                                                   +14   +30%
  +0.5%     +64 src/core/lib/iomgr/ev_poll_posix.cc                                                      +64  +0.5%
      [NEW]    +204 init_result(poll_args*) [clone .constprop.25]                                           +204  [NEW]
      [NEW]    +167 unref_by(grpc_fd*, int) [clone .constprop.24]                                           +167  [NEW]
      +3.1%     +58 cvfd_poll                                                                                +58  +3.1%
      +2.2%     +16 run_poll                                                                                 +16  +2.2%
  +1.7%     +48 src/core/lib/iomgr/timer_manager.cc                                                      +48  +1.7%
       +10%     +48 start_timer_thread_and_unlock                                                            +48   +10%
  +2.8%     +32 src/core/lib/iomgr/fork_posix.cc                                                         +32  +2.8%
      +4.3%     +24 grpc_prefork                                                                             +24  +4.3%
       +35%      +8 [Unmapped]                                                                                +8   +35%

  +0.1% +1.62Ki TOTAL                                                                                +11.8Ki  +0.1%


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

libgrpc++.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.0%     +32 [None]                                                                               +1.20Ki  +0.0%
  +2.0%     +80 src/cpp/server/dynamic_thread_pool.cc                                                    +80  +2.0%
       +38%     +85 grpc::DynamicThreadPool::DynamicThread::DynamicThread                                    +85   +38%
  +2.2%     +64 src/cpp/thread_manager/thread_manager.cc                                                 +64  +2.2%
       +22%     +64 grpc::ThreadManager::WorkerThread::WorkerThread                                          +64   +22%
  +0.0%     +16 src/cpp/server/health/default_health_check_service.cc                                    +16  +0.0%
      [NEW]    +244 std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<c    +244  [NEW]
      [NEW]    +200 void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >    +200  [NEW]
      +2.6%     +16 grpc::DefaultHealthCheckService::HealthCheckServiceImpl::HealthCheckServiceImpl          +16  +2.6%
      +3.3%      +8 [Unmapped]                                                                                +8  +3.3%

  +0.0%    +192 TOTAL                                                                                +1.35Ki  +0.0%



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

Objective-C binary sizes
*****************STATIC******************
  New size                      Old size
 2,020,841      Total (>)      2,020,224

 No significant differences in binary sizes

***************FRAMEWORKS****************
  New size                      Old size
11,154,951      Total (>)     11,154,227

 No significant differences in binary sizes


@grpc-testing
Copy link
Copy Markdown

Corrupt JSON data (indicates timeout or crash): 
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.new: 10
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.old: 10


[microbenchmarks] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.1%    +434 [None]                                                                               +10.6Ki  +0.1%
      +0.1%    +434 [Unmapped]                                                                           +10.6Ki  +0.1%
      [NEW]      +8 g_shutting_down_cv                                                                         0  [ = ]
      +6.7%      +8 g_alts_resource_dedicated                                                                  0  [ = ]
      [NEW]      +1 g_shutting_down                                                                            0  [ = ]
   +46%    +616 src/core/lib/surface/init.cc                                                            +616   +46%
      [NEW]    +500 grpc_shutdown_internal                                                                  +500  [NEW]
      [NEW]    +101 grpc_maybe_wait_for_async_shutdown                                                      +101  [NEW]
      +7.8%     +33 grpc_init                                                                                +33  +7.8%
       +70%     +32 do_basic_init                                                                            +32   +70%
   +26%    +256 src/core/lib/gprpp/thd_posix.cc                                                         +256   +26%
      [NEW]    +784 grpc_core::Thread::Thread                                                               +784  [NEW]
      [NEW]    +292 grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char co    +292  [NEW]
       +28%      +9 [Unmapped]                                                                                +9   +28%
  +2.8%    +128 src/core/lib/iomgr/executor.cc                                                          +128  +2.8%
      +6.6%     +88 GrpcExecutor::SetThreading                                                               +88  +6.6%
      +2.6%     +32 GrpcExecutor::Enqueue                                                                    +32  +2.6%
      +6.1%      +8 [Unmapped]                                                                                +8  +6.1%
  +8.1%     +78 src/core/tsi/alts/handshaker/alts_shared_resource.cc                                     +78  +8.1%
       +17%     +64 grpc_alts_shared_resource_dedicated_start                                                +64   +17%
       +30%     +14 _GLOBAL__sub_I_alts_shared_resource.cc                                                   +14   +30%
  +0.5%     +64 src/core/lib/iomgr/ev_poll_posix.cc                                                      +64  +0.5%
      [NEW]    +204 init_result(poll_args*) [clone .constprop.25]                                           +204  [NEW]
      [NEW]    +167 unref_by(grpc_fd*, int) [clone .constprop.24]                                           +167  [NEW]
      +3.1%     +58 cvfd_poll                                                                                +58  +3.1%
      +2.2%     +16 run_poll                                                                                 +16  +2.2%
  +1.7%     +48 src/core/lib/iomgr/timer_manager.cc                                                      +48  +1.7%
       +10%     +48 start_timer_thread_and_unlock                                                            +48   +10%
  +2.8%     +32 src/core/lib/iomgr/fork_posix.cc                                                         +32  +2.8%
      +4.3%     +24 grpc_prefork                                                                             +24  +4.3%
       +35%      +8 [Unmapped]                                                                                +8   +35%

  +0.1% +1.62Ki TOTAL                                                                                +11.8Ki  +0.1%


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

libgrpc++.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.0%     +32 [None]                                                                               +1.20Ki  +0.0%
  +2.0%     +80 src/cpp/server/dynamic_thread_pool.cc                                                    +80  +2.0%
       +38%     +85 grpc::DynamicThreadPool::DynamicThread::DynamicThread                                    +85   +38%
  +2.2%     +64 src/cpp/thread_manager/thread_manager.cc                                                 +64  +2.2%
       +22%     +64 grpc::ThreadManager::WorkerThread::WorkerThread                                          +64   +22%
  +0.0%     +16 src/cpp/server/health/default_health_check_service.cc                                    +16  +0.0%
      [NEW]    +244 std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<c    +244  [NEW]
      [NEW]    +200 void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >    +200  [NEW]
      +2.6%     +16 grpc::DefaultHealthCheckService::HealthCheckServiceImpl::HealthCheckServiceImpl          +16  +2.6%
      +3.3%      +8 [Unmapped]                                                                                +8  +3.3%

  +0.0%    +192 TOTAL                                                                                +1.35Ki  +0.0%



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

Objective-C binary sizes
*****************STATIC******************
  New size                      Old size
 2,020,841      Total (>)      2,020,224

 No significant differences in binary sizes

***************FRAMEWORKS****************
  New size                      Old size
11,154,957      Total (>)     11,154,231

 No significant differences in binary sizes


@grpc-testing
Copy link
Copy Markdown

Corrupt JSON data (indicates timeout or crash): 
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.new: 10
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.old: 10


[microbenchmarks] Performance differences noted:
Benchmark       cpu_time    real_time
--------------  ----------  -----------
BM_Zalloc/2048  -9%         -9%
BM_Zalloc/3072  -5%         -5%
BM_Zalloc/4096  -10%        -10%
BM_Zalloc/5120  -19%        -19%
BM_Zalloc/6144  -17%        -17%
BM_Zalloc/7168  -25%        -25%

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.1%    +434 [None]                                                                               +10.6Ki  +0.1%
      +0.1%    +434 [Unmapped]                                                                           +10.6Ki  +0.1%
      [NEW]      +8 g_shutting_down_cv                                                                         0  [ = ]
      +6.7%      +8 g_alts_resource_dedicated                                                                  0  [ = ]
      [NEW]      +1 g_shutting_down                                                                            0  [ = ]
   +46%    +616 src/core/lib/surface/init.cc                                                            +616   +46%
      [NEW]    +500 grpc_shutdown_internal                                                                  +500  [NEW]
      [NEW]    +101 grpc_maybe_wait_for_async_shutdown                                                      +101  [NEW]
      +7.8%     +33 grpc_init                                                                                +33  +7.8%
       +70%     +32 do_basic_init                                                                            +32   +70%
   +26%    +256 src/core/lib/gprpp/thd_posix.cc                                                         +256   +26%
      [NEW]    +784 grpc_core::Thread::Thread                                                               +784  [NEW]
      [NEW]    +292 grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char co    +292  [NEW]
       +28%      +9 [Unmapped]                                                                                +9   +28%
  +2.8%    +128 src/core/lib/iomgr/executor.cc                                                          +128  +2.8%
      +6.6%     +88 GrpcExecutor::SetThreading                                                               +88  +6.6%
      +2.6%     +32 GrpcExecutor::Enqueue                                                                    +32  +2.6%
      +6.1%      +8 [Unmapped]                                                                                +8  +6.1%
  +8.1%     +78 src/core/tsi/alts/handshaker/alts_shared_resource.cc                                     +78  +8.1%
       +17%     +64 grpc_alts_shared_resource_dedicated_start                                                +64   +17%
       +30%     +14 _GLOBAL__sub_I_alts_shared_resource.cc                                                   +14   +30%
  +0.5%     +64 src/core/lib/iomgr/ev_poll_posix.cc                                                      +64  +0.5%
      [NEW]    +204 init_result(poll_args*) [clone .constprop.25]                                           +204  [NEW]
      [NEW]    +167 unref_by(grpc_fd*, int) [clone .constprop.24]                                           +167  [NEW]
      +3.1%     +58 cvfd_poll                                                                                +58  +3.1%
      +2.2%     +16 run_poll                                                                                 +16  +2.2%
  +1.7%     +48 src/core/lib/iomgr/timer_manager.cc                                                      +48  +1.7%
       +10%     +48 start_timer_thread_and_unlock                                                            +48   +10%
  +2.8%     +32 src/core/lib/iomgr/fork_posix.cc                                                         +32  +2.8%
      +4.3%     +24 grpc_prefork                                                                             +24  +4.3%
       +35%      +8 [Unmapped]                                                                                +8   +35%

  +0.1% +1.62Ki TOTAL                                                                                +11.8Ki  +0.1%


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

libgrpc++.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.0%     +32 [None]                                                                               +1.20Ki  +0.0%
  +2.0%     +80 src/cpp/server/dynamic_thread_pool.cc                                                    +80  +2.0%
       +38%     +85 grpc::DynamicThreadPool::DynamicThread::DynamicThread                                    +85   +38%
  +2.2%     +64 src/cpp/thread_manager/thread_manager.cc                                                 +64  +2.2%
       +22%     +64 grpc::ThreadManager::WorkerThread::WorkerThread                                          +64   +22%
  +0.0%     +16 src/cpp/server/health/default_health_check_service.cc                                    +16  +0.0%
      [NEW]    +244 std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<c    +244  [NEW]
      [NEW]    +200 void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >    +200  [NEW]
      +2.6%     +16 grpc::DefaultHealthCheckService::HealthCheckServiceImpl::HealthCheckServiceImpl          +16  +2.6%
      +3.3%      +8 [Unmapped]                                                                                +8  +3.3%

  +0.0%    +192 TOTAL                                                                                +1.35Ki  +0.0%



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

Objective-C binary sizes
*****************STATIC******************
  New size                      Old size
 2,020,841      Total (>)      2,020,224

 No significant differences in binary sizes

***************FRAMEWORKS****************
  New size                      Old size
11,154,952      Total (>)     11,154,227

 No significant differences in binary sizes


@grpc-testing
Copy link
Copy Markdown

Corrupt JSON data (indicates timeout or crash): 
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.new: 10
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.old: 10


[microbenchmarks] Performance differences noted:
Benchmark       cpu_time    real_time
--------------  ----------  -----------
BM_Zalloc/2048  -8%         -8%
BM_Zalloc/3072  -14%        -14%
BM_Zalloc/4096  -11%        -11%
BM_Zalloc/5120  -20%        -20%
BM_Zalloc/6144  -15%        -15%
BM_Zalloc/7168  -23%        -23%

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.1%    +434 [None]                                                                               +10.6Ki  +0.1%
      +0.1%    +434 [Unmapped]                                                                           +10.6Ki  +0.1%
      [NEW]      +8 g_shutting_down_cv                                                                         0  [ = ]
      +6.7%      +8 g_alts_resource_dedicated                                                                  0  [ = ]
      [NEW]      +1 g_shutting_down                                                                            0  [ = ]
   +46%    +616 src/core/lib/surface/init.cc                                                            +616   +46%
      [NEW]    +500 grpc_shutdown_internal                                                                  +500  [NEW]
      [NEW]    +101 grpc_maybe_wait_for_async_shutdown                                                      +101  [NEW]
      +7.8%     +33 grpc_init                                                                                +33  +7.8%
       +70%     +32 do_basic_init                                                                            +32   +70%
   +26%    +256 src/core/lib/gprpp/thd_posix.cc                                                         +256   +26%
      [NEW]    +784 grpc_core::Thread::Thread                                                               +784  [NEW]
      [NEW]    +292 grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char co    +292  [NEW]
       +28%      +9 [Unmapped]                                                                                +9   +28%
  +2.8%    +128 src/core/lib/iomgr/executor.cc                                                          +128  +2.8%
      +6.6%     +88 GrpcExecutor::SetThreading                                                               +88  +6.6%
      +2.6%     +32 GrpcExecutor::Enqueue                                                                    +32  +2.6%
      +6.1%      +8 [Unmapped]                                                                                +8  +6.1%
  +8.1%     +78 src/core/tsi/alts/handshaker/alts_shared_resource.cc                                     +78  +8.1%
       +17%     +64 grpc_alts_shared_resource_dedicated_start                                                +64   +17%
       +30%     +14 _GLOBAL__sub_I_alts_shared_resource.cc                                                   +14   +30%
  +0.5%     +64 src/core/lib/iomgr/ev_poll_posix.cc                                                      +64  +0.5%
      [NEW]    +204 init_result(poll_args*) [clone .constprop.25]                                           +204  [NEW]
      [NEW]    +167 unref_by(grpc_fd*, int) [clone .constprop.24]                                           +167  [NEW]
      +3.1%     +58 cvfd_poll                                                                                +58  +3.1%
      +2.2%     +16 run_poll                                                                                 +16  +2.2%
  +1.7%     +48 src/core/lib/iomgr/timer_manager.cc                                                      +48  +1.7%
       +10%     +48 start_timer_thread_and_unlock                                                            +48   +10%
  +2.8%     +32 src/core/lib/iomgr/fork_posix.cc                                                         +32  +2.8%
      +4.3%     +24 grpc_prefork                                                                             +24  +4.3%
       +35%      +8 [Unmapped]                                                                                +8   +35%

  +0.1% +1.62Ki TOTAL                                                                                +11.8Ki  +0.1%


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

libgrpc++.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.0%     +32 [None]                                                                               +1.20Ki  +0.0%
  +2.0%     +80 src/cpp/server/dynamic_thread_pool.cc                                                    +80  +2.0%
       +38%     +85 grpc::DynamicThreadPool::DynamicThread::DynamicThread                                    +85   +38%
  +2.2%     +64 src/cpp/thread_manager/thread_manager.cc                                                 +64  +2.2%
       +22%     +64 grpc::ThreadManager::WorkerThread::WorkerThread                                          +64   +22%
  +0.0%     +16 src/cpp/server/health/default_health_check_service.cc                                    +16  +0.0%
      [NEW]    +244 std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<c    +244  [NEW]
      [NEW]    +200 void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >    +200  [NEW]
      +2.6%     +16 grpc::DefaultHealthCheckService::HealthCheckServiceImpl::HealthCheckServiceImpl          +16  +2.6%
      +3.3%      +8 [Unmapped]                                                                                +8  +3.3%

  +0.0%    +192 TOTAL                                                                                +1.35Ki  +0.0%



@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

Objective-C binary sizes
*****************STATIC******************
  New size                      Old size
 2,020,841      Total (>)      2,020,224

 No significant differences in binary sizes

***************FRAMEWORKS****************
  New size                      Old size
11,154,954      Total (>)     11,154,229

 No significant differences in binary sizes


@grpc-testing
Copy link
Copy Markdown

Corrupt JSON data (indicates timeout or crash): 
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.new: 10
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.old: 10


[microbenchmarks] Performance differences noted:
Benchmark       cpu_time    real_time
--------------  ----------  -----------
BM_Zalloc/2048  -12%        -12%
BM_Zalloc/3072  -7%         -7%
BM_Zalloc/4096  -19%        -19%
BM_Zalloc/6144  -19%        -19%
BM_Zalloc/7168  -15%        -15%

@grpc-testing
Copy link
Copy Markdown

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

libgrpc.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.1%    +402 [None]                                                                               +10.6Ki  +0.1%
      +0.1%    +402 [Unmapped]                                                                           +10.6Ki  +0.1%
      [NEW]      +8 g_shutting_down_cv                                                                         0  [ = ]
      +6.7%      +8 g_alts_resource_dedicated                                                                  0  [ = ]
      [NEW]      +1 g_shutting_down                                                                            0  [ = ]
   +46%    +616 src/core/lib/surface/init.cc                                                            +616   +46%
      [NEW]    +500 grpc_shutdown_internal                                                                  +500  [NEW]
      [NEW]    +101 grpc_maybe_wait_for_async_shutdown                                                      +101  [NEW]
      +7.8%     +33 grpc_init                                                                                +33  +7.8%
       +70%     +32 do_basic_init                                                                            +32   +70%
   +26%    +256 src/core/lib/gprpp/thd_posix.cc                                                         +256   +26%
      [NEW]    +784 grpc_core::Thread::Thread                                                               +784  [NEW]
      [NEW]    +292 grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char co    +292  [NEW]
       +28%      +9 [Unmapped]                                                                                +9   +28%
  +2.8%    +128 src/core/lib/iomgr/executor.cc                                                          +128  +2.8%
      +6.6%     +88 GrpcExecutor::SetThreading                                                               +88  +6.6%
      +2.6%     +32 GrpcExecutor::Enqueue                                                                    +32  +2.6%
      +6.1%      +8 [Unmapped]                                                                                +8  +6.1%
  +8.1%     +78 src/core/tsi/alts/handshaker/alts_shared_resource.cc                                     +78  +8.1%
       +17%     +64 grpc_alts_shared_resource_dedicated_start                                                +64   +17%
       +30%     +14 _GLOBAL__sub_I_alts_shared_resource.cc                                                   +14   +30%
  +0.5%     +64 src/core/lib/iomgr/ev_poll_posix.cc                                                      +64  +0.5%
      [NEW]    +204 init_result(poll_args*) [clone .constprop.25]                                           +204  [NEW]
      [NEW]    +167 unref_by(grpc_fd*, int) [clone .constprop.24]                                           +167  [NEW]
      +3.1%     +58 cvfd_poll                                                                                +58  +3.1%
      +2.2%     +16 run_poll                                                                                 +16  +2.2%
  +1.7%     +48 src/core/lib/iomgr/timer_manager.cc                                                      +48  +1.7%
       +10%     +48 start_timer_thread_and_unlock                                                            +48   +10%
  +2.8%     +32 src/core/lib/iomgr/fork_posix.cc                                                         +32  +2.8%
      +4.3%     +24 grpc_prefork                                                                             +24  +4.3%
       +35%      +8 [Unmapped]                                                                                +8   +35%

  +0.1% +1.59Ki TOTAL                                                                                +11.8Ki  +0.1%


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

libgrpc++.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.0%     +32 [None]                                                                               +1.23Ki  +0.0%
  +2.0%     +80 src/cpp/server/dynamic_thread_pool.cc                                                    +80  +2.0%
       +38%     +85 grpc::DynamicThreadPool::DynamicThread::DynamicThread                                    +85   +38%
  +2.2%     +64 src/cpp/thread_manager/thread_manager.cc                                                 +64  +2.2%
       +22%     +64 grpc::ThreadManager::WorkerThread::WorkerThread                                          +64   +22%
  +0.0%     +16 src/cpp/server/health/default_health_check_service.cc                                    +16  +0.0%
      [NEW]    +244 std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<c    +244  [NEW]
      [NEW]    +200 void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >    +200  [NEW]
      +2.6%     +16 grpc::DefaultHealthCheckService::HealthCheckServiceImpl::HealthCheckServiceImpl          +16  +2.6%
      +3.3%      +8 [Unmapped]                                                                                +8  +3.3%

  +0.0%    +192 TOTAL                                                                                +1.38Ki  +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.1%    +402 [None]                                                                               +10.6Ki  +0.1%
      +0.1%    +402 [Unmapped]                                                                           +10.6Ki  +0.1%
      [NEW]      +8 g_shutting_down_cv                                                                         0  [ = ]
      +6.7%      +8 g_alts_resource_dedicated                                                                  0  [ = ]
      [NEW]      +1 g_shutting_down                                                                            0  [ = ]
   +46%    +616 src/core/lib/surface/init.cc                                                            +616   +46%
      [NEW]    +500 grpc_shutdown_internal                                                                  +500  [NEW]
      [NEW]    +101 grpc_maybe_wait_for_async_shutdown                                                      +101  [NEW]
      +7.8%     +33 grpc_init                                                                                +33  +7.8%
       +70%     +32 do_basic_init                                                                            +32   +70%
   +26%    +256 src/core/lib/gprpp/thd_posix.cc                                                         +256   +26%
      [NEW]    +784 grpc_core::Thread::Thread                                                               +784  [NEW]
      [NEW]    +292 grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char co    +292  [NEW]
       +28%      +9 [Unmapped]                                                                                +9   +28%
  +2.8%    +128 src/core/lib/iomgr/executor.cc                                                          +128  +2.8%
      +6.6%     +88 GrpcExecutor::SetThreading                                                               +88  +6.6%
      +2.6%     +32 GrpcExecutor::Enqueue                                                                    +32  +2.6%
      +6.1%      +8 [Unmapped]                                                                                +8  +6.1%
  +8.1%     +78 src/core/tsi/alts/handshaker/alts_shared_resource.cc                                     +78  +8.1%
       +17%     +64 grpc_alts_shared_resource_dedicated_start                                                +64   +17%
       +30%     +14 _GLOBAL__sub_I_alts_shared_resource.cc                                                   +14   +30%
  +0.5%     +64 src/core/lib/iomgr/ev_poll_posix.cc                                                      +64  +0.5%
      [NEW]    +204 init_result(poll_args*) [clone .constprop.25]                                           +204  [NEW]
      [NEW]    +167 unref_by(grpc_fd*, int) [clone .constprop.24]                                           +167  [NEW]
      +3.1%     +58 cvfd_poll                                                                                +58  +3.1%
      +2.2%     +16 run_poll                                                                                 +16  +2.2%
  +1.7%     +48 src/core/lib/iomgr/timer_manager.cc                                                      +48  +1.7%
       +10%     +48 start_timer_thread_and_unlock                                                            +48   +10%
  +2.8%     +32 src/core/lib/iomgr/fork_posix.cc                                                         +32  +2.8%
      +4.3%     +24 grpc_prefork                                                                             +24  +4.3%
       +35%      +8 [Unmapped]                                                                                +8   +35%

  +0.1% +1.59Ki TOTAL                                                                                +11.8Ki  +0.1%


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

libgrpc++.so

     VM SIZE                                                                                            FILE SIZE
 ++++++++++++++ GROWING                                                                              ++++++++++++++
  +0.0%     +32 [None]                                                                               +1.23Ki  +0.0%
  +2.0%     +80 src/cpp/server/dynamic_thread_pool.cc                                                    +80  +2.0%
       +38%     +85 grpc::DynamicThreadPool::DynamicThread::DynamicThread                                    +85   +38%
  +2.2%     +64 src/cpp/thread_manager/thread_manager.cc                                                 +64  +2.2%
       +22%     +64 grpc::ThreadManager::WorkerThread::WorkerThread                                          +64   +22%
  +0.0%     +16 src/cpp/server/health/default_health_check_service.cc                                    +16  +0.0%
      [NEW]    +244 std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<c    +244  [NEW]
      [NEW]    +200 void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >    +200  [NEW]
      +2.6%     +16 grpc::DefaultHealthCheckService::HealthCheckServiceImpl::HealthCheckServiceImpl          +16  +2.6%
      +3.3%      +8 [Unmapped]                                                                                +8  +3.3%

  +0.0%    +192 TOTAL                                                                                +1.38Ki  +0.0%



@grpc-testing
Copy link
Copy Markdown

Objective-C binary sizes
*****************STATIC******************
  New size                      Old size
 2,020,995      Total (>)      2,020,378

 No significant differences in binary sizes

***************FRAMEWORKS****************
  New size                      Old size
11,174,817      Total (>)     11,174,081

 No significant differences in binary sizes


@grpc-testing
Copy link
Copy Markdown

[trickle] No significant performance differences

@grpc-testing
Copy link
Copy Markdown

Corrupt JSON data (indicates timeout or crash): 
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.new: 10
    bm_call_create.BM_IsolatedFilter_ClientChannelFilter_NoOp_.counters.old: 10


[microbenchmarks] Performance differences noted:
Benchmark       cpu_time    real_time
--------------  ----------  -----------
BM_Zalloc/2048  -13%        -13%
BM_Zalloc/5120  -18%        -18%
BM_Zalloc/6144  -26%        -26%
BM_Zalloc/7168  -25%        -25%

@grpc-testing
Copy link
Copy Markdown

Objective-C binary sizes
*****************STATIC******************
  New size                      Old size
 2,020,995      Total (>)      2,020,378

 No significant differences in binary sizes

***************FRAMEWORKS****************
  New size                      Old size
11,174,815      Total (>)     11,174,074

 No significant differences in binary sizes


@yang-g
Copy link
Copy Markdown
Contributor Author

yang-g commented Feb 15, 2019

Dusting this off. Tests are reasonably green. There are some python gevent test failures and the python team will take a look.

Copy link
Copy Markdown
Contributor

@ericgribkoff ericgribkoff left a comment

Choose a reason for hiding this comment

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

Python will need to use grpc_shutdown_blocking as well to allow fork support to work properly. I think this may also fix the failing gevent tests as well - I patched this locally with a switch to grpc_shutdown_blocking and was able to get "py27_gevent.test.unit._cython.cygrpc_test.TypeSmokeTest", which is failing on Kokoro, to pass.

Python (Cython) calls grpc_shutdown in several different files. I tested locally just by aliasing the function in src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi, but it would be better to not alias and just update the calls throughout the cython layer. I'm happy to add a commit to this branch if that's easier for you.


void grpc_prefork() {
skipped_handler = true;
grpc_maybe_wait_for_async_shutdown();
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 don't think this is necessary here (if it is, it needs to go after the check of grpc_is_initialized() below, as this may be called by the OS after core has shutdown).

Apologies for the lack of test coverage around this; still working through some unrelated issues, but #16513 is adding tests for the fork use case.

Core does not shutdown as part of its pre-fork handlers; Python (and PHP, as far as I know) shut down core in the child's post-fork handler, but that is handled outside of core's fork handlers.

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.

This looks good! My comments are mostly minor things.

Reviewed 31 of 31 files at r1.
Reviewable status: all files reviewed, 13 unresolved discussions (waiting on @ericgribkoff and @yang-g)


include/grpc/grpc.h, line 78 at r1 (raw file):

    The last call to grpc_shutdown will initiate cleaning up of grpc library
    internals, which can happen in another thread. Once the clean-up is done,
    no memory is used by grpc after this call returns, nor are any instructions

I think we should remove the "after this call returns" part, since it will now happen in another thread.


src/core/lib/gprpp/thd.h, line 53 at r1 (raw file):

   public:
    Options() : joinable_(true), tracked_(true) {}
    Options& set_joinable(bool joinable) {

Please add a comment documenting what this option means.


src/core/lib/gprpp/thd.h, line 57 at r1 (raw file):

      return *this;
    }
    Options& set_tracked(bool tracked) {

Same here.


src/core/lib/gprpp/thd_posix.cc, line 52 at r1 (raw file):

class ThreadInternalsPosix
    : public grpc_core::internal::ThreadInternalsInterface {

Not directly related to this PR, but I think you can remove all occurances of grpc_core:: in this file, since we're already inside of that namespace.


src/core/lib/gprpp/thd_windows.cc, line 51 at r1 (raw file):

  void* arg;               /* argument to a thread */
  HANDLE join_event;       /* the join event */
  bool joinable;           /* whether it is joinable */

Do we not need to support tracked threads on Windows?


src/core/lib/gprpp/thd_windows.cc, line 147 at r1 (raw file):

}  // namespace

namespace grpc_core {

Not directly related to this PR, but I think this should probably move up to line 44, so that all of the code in this file is in the grpc_core namespace.


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

void grpc_shutdown_internal(void* ignored) {
  GRPC_API_TRACE("grpc_shutdown_internal", 0, ());
  gpr_mu_lock(&g_init_mu);

Suggest using grpc_core::MutexLock here, so that we don't need to explicitly unlock in each branch below.

We can actually probably use it throughout this file.


test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc, line 285 at r1 (raw file):

    GRPC_COMBINER_UNREF(g_combiner, "test");
  }
  grpc_shutdown();

Could probably just call grpc_shutdown_blocking() here.


test/core/end2end/fuzzers/api_fuzzer.cc, line 1204 at r1 (raw file):

  grpc_resource_quota_unref(g_resource_quota);

  grpc_shutdown();

Could probably just call grpc_shutdown_blocking() here.


test/core/handshake/readahead_handshaker_server_ssl.cc, line 87 at r1 (raw file):

  const char* full_alpn_list[] = {"grpc-exp", "h2"};
  GPR_ASSERT(server_ssl_test(full_alpn_list, 2, "grpc-exp"));
  grpc_shutdown();

Could probably just use grpc_shutdown_blocking() here.


test/core/util/memory_counters.h, line 24 at r1 (raw file):

#include <grpc/support/atm.h>

struct grpc_memory_counters {

Are we still using this old API anywhere outside of this module? If not, consider moving it to the .cc file.

If you do that, then maybe also consider renaming this module to leak_detector.{h,cc}.


test/core/util/memory_counters.h, line 43 at r1 (raw file):

class LeakDetector {
 public:
  explicit LeakDetector(bool enable);

Is there ever any use-case for passing enable=false?

Copy link
Copy Markdown
Contributor Author

@yang-g yang-g left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 13 unresolved discussions (waiting on @ericgribkoff and @markdroth)


include/grpc/grpc.h, line 78 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

I think we should remove the "after this call returns" part, since it will now happen in another thread.

Done.


src/core/lib/gprpp/thd.h, line 53 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Please add a comment documenting what this option means.

Done.


src/core/lib/gprpp/thd.h, line 57 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Same here.

Done. Removed.


src/core/lib/gprpp/thd_posix.cc, line 52 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Not directly related to this PR, but I think you can remove all occurances of grpc_core:: in this file, since we're already inside of that namespace.

Done.


src/core/lib/gprpp/thd_windows.cc, line 51 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Do we not need to support tracked threads on Windows?

I have removed tracked threads because python and php (which support forking) have moved to grpc_shutdown_blocking.


src/core/lib/gprpp/thd_windows.cc, line 147 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Not directly related to this PR, but I think this should probably move up to line 44, so that all of the code in this file is in the grpc_core namespace.

Done.


src/core/lib/iomgr/fork_posix.cc, line 52 at r1 (raw file):

Previously, ericgribkoff (Eric Gribkoff) wrote…

I don't think this is necessary here (if it is, it needs to go after the check of grpc_is_initialized() below, as this may be called by the OS after core has shutdown).

Apologies for the lack of test coverage around this; still working through some unrelated issues, but #16513 is adding tests for the fork use case.

Core does not shutdown as part of its pre-fork handlers; Python (and PHP, as far as I know) shut down core in the child's post-fork handler, but that is handled outside of core's fork handlers.

Done.


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

Previously, markdroth (Mark D. Roth) wrote…

Suggest using grpc_core::MutexLock here, so that we don't need to explicitly unlock in each branch below.

We can actually probably use it throughout this file.

Done.


test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc, line 285 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Could probably just call grpc_shutdown_blocking() here.

Done.


test/core/end2end/fuzzers/api_fuzzer.cc, line 1204 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Could probably just call grpc_shutdown_blocking() here.

Done.


test/core/handshake/readahead_handshaker_server_ssl.cc, line 87 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Could probably just use grpc_shutdown_blocking() here.

Done.


test/core/util/memory_counters.h, line 24 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Are we still using this old API anywhere outside of this module? If not, consider moving it to the .cc file.

If you do that, then maybe also consider renaming this module to leak_detector.{h,cc}.

We have direct uses of the API in tests such as test/core/memory_usage/client.cc, where multiple snapshots are taken during the test.


test/core/util/memory_counters.h, line 43 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Is there ever any use-case for passing enable=false?

In places like fuzzers, we have a global boolean to decided whether to enable leak check and I believe that value can be mutated externally. This argument is trying to capture that.

Copy link
Copy Markdown
Contributor Author

@yang-g yang-g left a comment

Choose a reason for hiding this comment

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

Reviewable status: 19 of 40 files reviewed, 13 unresolved discussions (waiting on @ericgribkoff and @markdroth)


src/core/lib/gprpp/thd.h, line 57 at r1 (raw file):

Previously, yang-g (Yang Gao) wrote…

Done. Removed.

I put tracked option back because the Fork Inc/DecThreadCount touches something global out of a lock and we still need to use tracked to exclude the detached thread.


src/core/lib/gprpp/thd_windows.cc, line 51 at r1 (raw file):

Previously, yang-g (Yang Gao) wrote…

I have removed tracked threads because python and php (which support forking) have moved to grpc_shutdown_blocking.

We are not doing fork thread counting and thus do not need tracked in this file.


src/core/lib/gprpp/thd_windows.cc, line 147 at r1 (raw file):

Previously, yang-g (Yang Gao) wrote…

Done.

It is a bit complicated because of the global function referenced the thread local variable. So I leave it as is.

@yang-g
Copy link
Copy Markdown
Contributor Author

yang-g commented Feb 20, 2019

@markdroth @ericgribkoff PTAL Thanks.

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.

Remaining comments are minor; feel free to merge after addressing.

Reviewed 21 of 21 files at r2.
Reviewable status: 39 of 40 files reviewed, 3 unresolved discussions (waiting on @ericgribkoff, @markdroth, and @yang-g)


src/core/lib/iomgr/fork_posix.cc, line 38 at r3 (raw file):

#include "src/core/lib/iomgr/timer_manager.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
#include "src/core/lib/surface/init.h"

This include is probably not needed anymore.


test/core/json/fuzzer.cc, line 34 at r3 (raw file):

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  char* s;
  grpc_core::testing::LeakDetector leak_detector(leak_check);

The old code didn't use the leak_check variable. Was this a pre-existing bug, or should this be changed to use true instead?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lang/core release notes: yes Indicates if PR needs to be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants