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

Initial Gevent Compatibility #14561

Merged
merged 2 commits into from
Mar 28, 2018
Merged

Initial Gevent Compatibility #14561

merged 2 commits into from
Mar 28, 2018

Conversation

kpayson64
Copy link
Contributor

Addresses #4629

This PR needs to be cleaned up and broken into much smaller PRs for review, but should contain the basic components of gevent compatibility.

from gevent import monkey
monkey.patch_all()

import grpc._cython.cygrpc
grpc._cython.cygrpc.init_grpc_gevent()

Adding the above lines should make gRPC work with gevent.

@kpayson64
Copy link
Contributor Author

@a11r @dgquintas @markdroth
Please ignore the auto review-assign. I will be breaking this into smaller PRs but wanted to verify the tests are passing on Kokoro here.

@grpc-testing
Copy link

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

libgrpc.so

     VM SIZE                                                                                     FILE SIZE
 ++++++++++++++ GROWING                                                                       ++++++++++++++
  +2.3% +14.0Ki [None]                                                                         +170Ki  +2.5%
      +2.4% +13.3Ki [Unmapped]                                                                     +170Ki  +2.5%
       +17%    +176 vtable                                                                           +176   +17%
      [NEW]     +72 custom_tcp_server_vtable                                                          +72  [NEW]
      [NEW]     +72 grpc_default_tcp_server_vtable                                                    +72  [NEW]
      [NEW]     +64 custom_pollset_vtable                                                             +64  [NEW]
      [NEW]     +64 grpc_default_pollset_vtable                                                       +64  [NEW]
      [NEW]     +56 [Other]                                                                           +24  [NEW]
      [NEW]     +48 custom_timer_vtable                                                               +48  [NEW]
      [NEW]     +48 grpc_default_pollset_set_vtable                                                   +48  [NEW]
      [NEW]     +48 grpc_default_timer_vtable                                                         +48  [NEW]
      +1.4%     +16 [None]                                                                              0  [ = ]
      [NEW]     +16 ares_resolver                                                                     +16  [NEW]
      [NEW]     +16 custom_resolver_vtable                                                            +16  [NEW]
      [NEW]     +16 grpc_default_resolver_vtable                                                      +16  [NEW]
      [NEW]      +8 timer_vtable                                                                       +8  [NEW]
      [NEW]      +8 client_vtable                                                                      +8  [NEW]
      [NEW]      +8 poller_vtable                                                                       0  [ = ]
      [NEW]      +8 server_vtable                                                                      +8  [NEW]
      [NEW]      +8 pollset_vtable                                                                     +8  [NEW]
      [NEW]      +8 resolver_vtable                                                                    +8  [NEW]
      [NEW]      +8 custom_timer_impl                                                                   0  [ = ]
  [NEW] +3.70Ki src/core/lib/iomgr/tcp_server_custom.cc                                       +3.70Ki  [NEW]
      [NEW] +1.25Ki tcp_server_add_port                                                           +1.25Ki  [NEW]
      [NEW]    +750 grpc_custom_accept_callback                                                      +750  [NEW]
      [NEW]    +469 tcp_server_unref                                                                 +469  [NEW]
      [NEW]    +382 tcp_server_create                                                                +382  [NEW]
      [NEW]    +274 tcp_server_start                                                                 +274  [NEW]
      [NEW]    +258 grpc_custom_close_server_callback                                                +258  [NEW]
      [NEW]    +139 finish_shutdown                                                                  +139  [NEW]
      [NEW]     +86 [Unmapped]                                                                        +86  [NEW]
      [NEW]     +71 tcp_server_shutdown_starting_add                                                  +71  [NEW]
      [NEW]     +63 tcp_server_shutdown_listeners                                                     +63  [NEW]
      [NEW]     +14 tcp_server_ref                                                                    +14  [NEW]
      [NEW]      +6 tcp_server_port_fd                                                                 +6  [NEW]
      [NEW]      +3 tcp_server_port_fd_count                                                           +3  [NEW]
  [NEW] +3.22Ki src/core/lib/iomgr/tcp_custom.cc                                              +3.22Ki  [NEW]
      [NEW]    +633 endpoint_write                                                                   +633  [NEW]
      [NEW]    +449 custom_tcp_endpoint_create                                                       +449  [NEW]
      [NEW]    +422 grpc_custom_read_callback                                                        +422  [NEW]
      [NEW]    +367 call_read_cb                                                                     +367  [NEW]
      [NEW]    +343 grpc_custom_write_callback                                                       +343  [NEW]
      [NEW]    +271 grpc_custom_close_callback                                                       +271  [NEW]
      [NEW]    +234 tcp_read_allocation_done                                                         +234  [NEW]
      [NEW]    +136 [Unmapped]                                                                       +136  [NEW]
      [NEW]    +133 endpoint_shutdown                                                                +133  [NEW]
      [NEW]    +105 tcp_unref                                                                        +105  [NEW]
      [NEW]    +103 endpoint_read                                                                    +103  [NEW]
      [NEW]     +42 grpc_custom_endpoint_init                                                         +42  [NEW]
      [NEW]     +30 endpoint_destroy                                                                  +30  [NEW]
      [NEW]     +12 endpoint_get_peer                                                                 +12  [NEW]
      [NEW]      +6 endpoint_get_fd                                                                    +6  [NEW]
      [NEW]      +5 endpoint_get_resource_user                                                         +5  [NEW]
      [NEW]      +2 endpoint_add_to_pollset                                                            +2  [NEW]
      [NEW]      +2 endpoint_add_to_pollset_set                                                        +2  [NEW]
      [NEW]      +2 endpoint_delete_from_pollset_set                                                   +2  [NEW]
  [NEW] +1.83Ki src/core/lib/iomgr/resolve_address_custom.cc                                  +1.83Ki  [NEW]
      [NEW]    +382 grpc_custom_resolve_callback                                                     +382  [NEW]
      [NEW]    +367 blocking_resolve_address_impl                                                    +367  [NEW]
      [NEW]    +322 resolve_address_impl                                                             +322  [NEW]
      [NEW]    +288 try_split_host_port                                                              +288  [NEW]
      [NEW]    +270 retry_named_port_failure                                                         +270  [NEW]
      [NEW]    +205 handle_addrinfo_result                                                           +205  [NEW]
      [NEW]     +22 [Unmapped]                                                                        +22  [NEW]
      [NEW]     +19 grpc_custom_resolver_init                                                         +19  [NEW]
  [NEW]   +1022 src/core/lib/iomgr/tcp_client_custom.cc                                         +1022  [NEW]
      [NEW]    +396 tcp_connect                                                                      +396  [NEW]
      [NEW]    +382 grpc_custom_connect_callback                                                     +382  [NEW]
      [NEW]    +130 uv_tc_on_alarm                                                                   +130  [NEW]
      [NEW]     +94 uv_tcp_connect_cleanup                                                            +94  [NEW]
      [NEW]     +20 [Unmapped]                                                                        +20  [NEW]
  [NEW]    +707 src/core/lib/iomgr/timer_custom.cc                                               +707  [NEW]
      [NEW]    +337 grpc_custom_timer_callback                                                       +337  [NEW]
      [NEW]    +169 timer_init                                                                       +169  [NEW]
      [NEW]     +92 timer_cancel                                                                      +92  [NEW]
      [NEW]     +81 [Unmapped]                                                                        +81  [NEW]
      [NEW]     +19 grpc_custom_timer_init                                                            +19  [NEW]
      [NEW]      +3 timer_check                                                                        +3  [NEW]
      [NEW]      +2 timer_list_init                                                                    +2  [NEW]
      [NEW]      +2 timer_consume_kick                                                                 +2  [NEW]
      [NEW]      +2 timer_list_shutdown                                                                +2  [NEW]
  [NEW]    +351 src/core/lib/iomgr/iomgr_custom.cc                                               +351  [NEW]
      [NEW]    +227 iomgr_platform_init                                                              +227  [NEW]
      [NEW]     +63 grpc_custom_iomgr_init                                                            +63  [NEW]
      [NEW]     +46 [Unmapped]                                                                        +46  [NEW]
      [NEW]      +8 custom_iomgr_platform_vtable                                                       +8  [NEW]
      [NEW]      +5 iomgr_platform_shutdown                                                            +5  [NEW]
      [NEW]      +2 iomgr_platform_flush                                                               +2  [NEW]
  [NEW]    +339 src/core/lib/iomgr/pollset_custom.cc                                             +339  [NEW]
      [NEW]    +137 pollset_work                                                                     +137  [NEW]
      [NEW]     +65 [Unmapped]                                                                        +65  [NEW]
      [NEW]     +39 pollset_shutdown                                                                  +39  [NEW]
      [NEW]     +28 pollset_init                                                                      +28  [NEW]
      [NEW]     +21 pollset_kick                                                                      +21  [NEW]
      [NEW]     +19 grpc_custom_pollset_init                                                          +19  [NEW]
      [NEW]     +10 pollset_global_shutdown                                                           +10  [NEW]
      [NEW]      +9 pollset_global_init                                                                +9  [NEW]
      [NEW]      +6 pollset_size                                                                       +6  [NEW]
      [NEW]      +5 pollset_destroy                                                                    +5  [NEW]
  +9.0%    +175 src/core/lib/iomgr/sockaddr_utils.cc                                             +175  +9.0%
      [NEW]    +173 grpc_string_to_sockaddr                                                          +173  [NEW]
      +2.1%      +2 [Unmapped]                                                                         +2  +2.1%
  [NEW]    +152 src/core/lib/iomgr/tcp_server.cc                                                 +152  [NEW]
      [NEW]     +55 [Unmapped]                                                                        +55  [NEW]
      [NEW]     +10 grpc_tcp_server_ref                                                               +10  [NEW]
      [NEW]     +10 grpc_tcp_server_start                                                             +10  [NEW]
      [NEW]     +10 grpc_tcp_server_unref                                                             +10  [NEW]
      [NEW]     +10 grpc_tcp_server_port_fd                                                           +10  [NEW]
      [NEW]     +10 grpc_tcp_server_add_port                                                          +10  [NEW]
      [NEW]     +10 grpc_tcp_server_port_fd_count                                                     +10  [NEW]
      [NEW]     +10 grpc_tcp_server_shutdown_listeners                                                +10  [NEW]
      [NEW]     +10 grpc_tcp_server_shutdown_starting_add                                             +10  [NEW]
      [NEW]      +9 grpc_tcp_server_create                                                             +9  [NEW]
      [NEW]      +8 grpc_set_tcp_server_impl                                                           +8  [NEW]
  [NEW]    +138 src/core/lib/iomgr/pollset.cc                                                    +138  [NEW]
      [NEW]     +51 [Unmapped]                                                                        +51  [NEW]
      [NEW]     +10 grpc_pollset_init                                                                 +10  [NEW]
      [NEW]     +10 grpc_pollset_kick                                                                 +10  [NEW]
      [NEW]     +10 grpc_pollset_size                                                                 +10  [NEW]
      [NEW]     +10 grpc_pollset_work                                                                 +10  [NEW]
      [NEW]     +10 grpc_pollset_destroy                                                              +10  [NEW]
      [NEW]     +10 grpc_pollset_shutdown                                                             +10  [NEW]
      [NEW]     +10 grpc_pollset_global_shutdown                                                      +10  [NEW]
      [NEW]      +9 grpc_pollset_global_init                                                           +9  [NEW]
      [NEW]      +8 grpc_set_pollset_vtable                                                            +8  [NEW]
  [NEW]    +108 src/core/lib/iomgr/pollset_set_custom.cc                                         +108  [NEW]
      [NEW]     +80 [Unmapped]                                                                        +80  [NEW]
      [NEW]     +12 grpc_custom_pollset_set_init                                                      +12  [NEW]
      [NEW]      +6 pollset_set_create                                                                 +6  [NEW]
      [NEW]      +2 pollset_set_destroy                                                                +2  [NEW]
      [NEW]      +2 pollset_set_add_pollset                                                            +2  [NEW]
      [NEW]      +2 pollset_set_del_pollset                                                            +2  [NEW]
      [NEW]      +2 pollset_set_add_pollset_set                                                        +2  [NEW]
      [NEW]      +2 pollset_set_del_pollset_set                                                        +2  [NEW]
  [NEW]    +106 src/core/lib/iomgr/pollset_set.cc                                                +106  [NEW]
      [NEW]     +39 [Unmapped]                                                                        +39  [NEW]
      [NEW]     +10 grpc_pollset_set_destroy                                                          +10  [NEW]
      [NEW]     +10 grpc_pollset_set_add_pollset                                                      +10  [NEW]
      [NEW]     +10 grpc_pollset_set_del_pollset                                                      +10  [NEW]
      [NEW]     +10 grpc_pollset_set_add_pollset_set                                                  +10  [NEW]
      [NEW]     +10 grpc_pollset_set_del_pollset_set                                                  +10  [NEW]
      [NEW]      +9 grpc_pollset_set_create                                                            +9  [NEW]
      [NEW]      +8 grpc_set_pollset_set_vtable                                                        +8  [NEW]
  [NEW]    +106 src/core/lib/iomgr/timer.cc                                                      +106  [NEW]
      [NEW]     +39 [Unmapped]                                                                        +39  [NEW]
      [NEW]     +10 grpc_timer_check                                                                  +10  [NEW]
      [NEW]     +10 grpc_timer_cancel                                                                 +10  [NEW]
      [NEW]     +10 grpc_timer_list_init                                                              +10  [NEW]
      [NEW]     +10 grpc_timer_consume_kick                                                           +10  [NEW]
      [NEW]     +10 grpc_timer_list_shutdown                                                          +10  [NEW]
      [NEW]      +9 grpc_timer_init                                                                    +9  [NEW]
      [NEW]      +8 grpc_set_timer_impl                                                                +8  [NEW]
  [NEW]     +90 src/core/lib/iomgr/iomgr_internal.cc                                              +90  [NEW]
      [NEW]     +41 grpc_iomgr_platform_init                                                          +41  [NEW]
      [NEW]     +21 [Unmapped]                                                                        +21  [NEW]
      [NEW]     +10 grpc_iomgr_platform_flush                                                         +10  [NEW]
      [NEW]     +10 grpc_iomgr_platform_shutdown                                                      +10  [NEW]
      [NEW]      +8 grpc_set_iomgr_platform_vtable                                                     +8  [NEW]
  [NEW]     +74 src/core/lib/iomgr/resolve_address.cc                                             +74  [NEW]
      [NEW]     +27 grpc_resolved_addresses_destroy                                                   +27  [NEW]
      [NEW]     +20 [Unmapped]                                                                        +20  [NEW]
      [NEW]     +10 grpc_blocking_resolve_address                                                     +10  [NEW]
      [NEW]      +9 grpc_resolve_address                                                               +9  [NEW]
      [NEW]      +8 grpc_set_resolver_impl                                                             +8  [NEW]
  +0.4%     +47 [Other]                                                                           +47  +0.4%
  +3.9%     +38 src/core/ext/filters/client_channel/backup_poller.cc                              +38  +3.9%
      +8.6%     +19 run_poller                                                                        +19  +8.6%
       +21%     +10 [Unmapped]                                                                        +10   +21%
      +3.0%      +6 grpc_client_channel_stop_backup_polling                                            +6  +3.0%
      +0.9%      +3 grpc_client_channel_start_backup_polling                                           +3  +0.9%
  +2.3%     +32 src/core/lib/iomgr/ev_posix.cc                                                    +32  +2.3%
       +15%     +28 [Unmapped]                                                                        +28   +15%
      [NEW]     +13 pollset_set_destroy                                                               +13  [NEW]
      [NEW]     +13 pollset_set_add_pollset                                                           +13  [NEW]
      [NEW]     +13 pollset_set_del_pollset                                                           +13  [NEW]
      [NEW]     +13 pollset_set_add_pollset_set                                                       +13  [NEW]
      [NEW]     +13 pollset_set_del_pollset_set                                                       +13  [NEW]
      [NEW]     +11 pollset_size                                                                      +11  [NEW]
      [NEW]     +10 pollset_init                                                                      +10  [NEW]
      [NEW]     +10 pollset_kick                                                                      +10  [NEW]
      [NEW]     +10 pollset_work                                                                      +10  [NEW]
      [NEW]     +10 pollset_destroy                                                                   +10  [NEW]
      [NEW]     +10 pollset_shutdown                                                                  +10  [NEW]
      [NEW]     +10 pollset_set_create                                                                +10  [NEW]
      [NEW]      +2 pollset_global_init                                                                +2  [NEW]
      [NEW]      +2 pollset_global_shutdown                                                            +2  [NEW]
  [NEW]     +24 src/core/lib/iomgr/tcp_client.cc                                                  +24  [NEW]
      [NEW]      +9 grpc_tcp_client_connect                                                            +9  [NEW]
      [NEW]      +8 grpc_set_tcp_client_impl                                                           +8  [NEW]
      [NEW]      +7 [Unmapped]                                                                         +7  [NEW]
   +33%     +22 src/core/lib/iomgr/iomgr_posix.cc                                                 +22   +33%
      [NEW]     +18 iomgr_platform_init                                                               +18  [NEW]
      [NEW]     +18 iomgr_platform_shutdown                                                           +18  [NEW]
       +50%     +14 [Unmapped]                                                                        +14   +50%
      [NEW]      +8 grpc_default_iomgr_platform_vtable                                                 +8  [NEW]
      [NEW]      +2 iomgr_platform_flush                                                               +2  [NEW]

 -------------- SHRINKING                                                                     --------------
  -2.3%     -41 src/core/lib/iomgr/resolve_address_posix.cc                                       -41  -2.3%
      [DEL] -1.44Ki blocking_resolve_address_impl                                                 -1.44Ki  [DEL]
      [DEL]    -165 resolve_address_impl                                                             -165  [DEL]
      [DEL]     -27 grpc_resolved_addresses_destroy                                                   -27  [DEL]
      -8.9%      -8 do_request_thread                                                                  -8  -8.9%
     -22.2%      -6 [Unmapped]                                                                         -6 -22.2%
  -0.5%     -18 src/core/lib/iomgr/tcp_client_posix.cc                                            -18  -0.5%
      [DEL]    -215 tcp_client_connect_impl                                                          -215  [DEL]
     -18.4%      -9 [Unmapped]                                                                         -9 -18.4%
      [DEL]      -9 grpc_tcp_client_connect                                                            -9  [DEL]
  -0.6%     -16 src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc           -16  -0.6%
      -8.6%     -12 [Unmapped]                                                                        -12  -8.6%
      -2.8%      -4 grpc_core::(anonymous namespace)::NativeDnsResolver::StartResolvingLocked          -4  -2.8%

  +2.1% +26.1Ki TOTAL                                                                          +182Ki  +2.4%


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

libgrpc++.so

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

 -------------- SHRINK --------------
  [ = ]       0 [None] -2.07Ki  -0.0%

  [ = ]       0 TOTAL  -2.07Ki  -0.0%



@grpc-testing
Copy link

[trickle] No significant performance differences

@grpc-testing
Copy link

[microbenchmarks] Performance differences noted:
Benchmark                                                    call_initial_size-median
-----------------------------------------------------------  --------------------------
BM_StreamingPingPong<TCP, NoOpMutator, NoOpMutator>/0/2      +8%
BM_StreamingPingPong<TCP, NoOpMutator, NoOpMutator>/1/2      +8%
BM_StreamingPingPong<TCP, NoOpMutator, NoOpMutator>/32768/2  +6%
BM_StreamingPingPong<TCP, NoOpMutator, NoOpMutator>/4096/2   +7%
BM_StreamingPingPong<TCP, NoOpMutator, NoOpMutator>/512/2    +7%
BM_StreamingPingPong<TCP, NoOpMutator, NoOpMutator>/64/2     +7%
BM_StreamingPingPong<TCP, NoOpMutator, NoOpMutator>/8/2      +7%

@grpc-testing
Copy link

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

libgrpc.so

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

  [ = ]       0        0  [ = ]


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



1 similar comment
@grpc-testing
Copy link

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

libgrpc.so

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

  [ = ]       0        0  [ = ]


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link

[trickle] No significant performance differences

1 similar comment
@grpc-testing
Copy link

[trickle] No significant performance differences

@grpc-testing
Copy link

[microbenchmarks] No significant performance differences

1 similar comment
@grpc-testing
Copy link

[microbenchmarks] No significant performance differences

@@ -1,4 +1,4 @@
cygrpc.c
cygrpc.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

s/cpp/cc ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cython only generates .cpp files (You can't tell it to generate cc files)

Also, I think you got dragged into this PR because I touched and then reverted a file you are an OWNER for, but I can't remove you as a reviewer (so you can ignore this pr)

def init_grpc_gevent():
_initialize_grpc_gevent_loop(False)

def initialize_grpc_gevent_loop_test():

Choose a reason for hiding this comment

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

Are we mixing production code and test code? How hard did you look at keeping them separate? Should we file a low-priority cleanup issue documenting that we're mixing production code and test code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test code was a vestige of running the c-core end-to-end tests with gevent.

Because that is not part of this PR, I've removed it for now.


g_event = gevent_event.Event()

cdef void init_loop() with gil:

Choose a reason for hiding this comment

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

The Python subcodebase consistently maintains definition-before-use order (in both Cython and Python). Can that be maintained in this added code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# distutils: language=c++

Choose a reason for hiding this comment

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

I don't understand this and it isn't mentioned in the commit log message. What's going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a comment in the commit message.

Because some c++ from core ends up leaking in certain headers, I needed to change the cython extension to be built with c++.

@@ -50,7 +50,8 @@
'build_package_protos': grpc_tools.command.BuildPackageProtos,
'build_py': commands.BuildPy,
'run_interop': commands.RunInterop,
'test_lite': commands.TestLite
'test_lite': commands.TestLite,
'test_gevent': commands.TestGevent

Choose a reason for hiding this comment

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

Always include the comma after the last element in multiline collection and dictionary literals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@kpayson64
Copy link
Contributor Author

Addressed comments and fixed some sanity failures

@grpc-testing
Copy link

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

libgrpc.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.7%     +14 src/core/lib/iomgr/sockaddr_utils.cc     +14  +0.7%
      +8.1%     +14 grpc_string_to_sockaddr                  +14  +8.1%

 -------------- SHRINKING                            --------------
  -0.0%     -14 [None]                                   -14  -0.0%

  [ = ]       0 TOTAL                                      0  [ = ]


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



1 similar comment
@grpc-testing
Copy link

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

libgrpc.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.7%     +14 src/core/lib/iomgr/sockaddr_utils.cc     +14  +0.7%
      +8.1%     +14 grpc_string_to_sockaddr                  +14  +8.1%

 -------------- SHRINKING                            --------------
  -0.0%     -14 [None]                                   -14  -0.0%

  [ = ]       0 TOTAL                                      0  [ = ]


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link

[trickle] No significant performance differences

@grpc-testing
Copy link

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

libgrpc.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.7%     +14 src/core/lib/iomgr/sockaddr_utils.cc     +14  +0.7%
      +8.1%     +14 grpc_string_to_sockaddr                  +14  +8.1%

 -------------- SHRINKING                            --------------
  -0.0%     -14 [None]                                   -14  -0.0%

  [ = ]       0 TOTAL                                      0  [ = ]


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link

[trickle] No significant performance differences

@kpayson64
Copy link
Contributor Author

It looks like Eventlet is a separate event loop than gevent, so no this PR is not sufficient to support it.

However, since it provides a monkey_patch function, it may be possible to adapt this PR to later support it.

Copy link
Member

@nathanielmanistaatgoogle nathanielmanistaatgoogle left a comment

Choose a reason for hiding this comment

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

I think this is my last round of substantive comments. I certainly hope that it is.

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""gRPC's Python gEvent APIs"""

Choose a reason for hiding this comment

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

Missing period at the end of this doc string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

def init_gevent():
"""Patches gRPC's libraries to be compatible with gevent.

This must be called AFTER the python standard lib has been patched,

Choose a reason for hiding this comment

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

This line (and the other two-space-indented lines in this doc string) should be four-spaces-indented.

I think this is one of those things where yapf isn't yet smart enough to do it, but mercifully it is smart enough to avoid undoing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@@ -181,6 +187,13 @@ def try_set_handler(name, handler):
# Run the tests
result.startTestRun()
for augmented_case in augmented_cases:
skip_test = False

Choose a reason for hiding this comment

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

Move this assignment to an else: attached to the for:.

(Then see if the local field doesn't just evaporate entirely if the continue is also moved into the else:?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

@@ -237,6 +237,7 @@ def testUpDown(self):
self.assertIsNotNone(service.servicer_methods)
self.assertIsNotNone(service.server)
self.assertIsNotNone(service.stub)
service.server.stop(None)

Choose a reason for hiding this comment

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

I think the changes to this file and _split_definitions_test are worth breaking out into a separate pull request.

My apologies for not calling it out earlier in review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is important context to this change in this PR. I've broken it into a separate commit for some separation though.

.gitignore Outdated
@@ -15,7 +15,7 @@ python_pylint_venv/
htmlcov/
dist/
*.egg
py27/
py27*/

Choose a reason for hiding this comment

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

Ah, okay.

I have an awful feeling that py3[0-9]* was intended to be a regular expression rather than a glob. Knowing now that they are globs, can we rewrite these to only capture what we really intend to capture? It'd be nice in an explicitly self-documenting kind of way if these contained _native and _gevent in them.

@likeyiyy
Copy link

When will the PR be merged? Thanks

@nathanielmanistaatgoogle
Copy link
Member

@likeyiyy, @201tank: I think we'll merge this after all code reviewers are satisfied with its content and the pull request passes all preintegration tests, just like we'd expect to be the case before merging any other pull request.

Relying on garbage collection to stop servers breaks with gevent.
Because some cpp code ends up leaking into cython, we change
the cython generator to generate cpp code.
@grpc-testing
Copy link

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

libgrpc.so

     VM SIZE                                            FILE SIZE
 ++++++++++++++ GROWING                              ++++++++++++++
  +0.7%     +14 src/core/lib/iomgr/sockaddr_utils.cc     +14  +0.7%
      +8.1%     +14 grpc_string_to_sockaddr                  +14  +8.1%

 -------------- SHRINKING                            --------------
  -0.0%     -14 [None]                                   -14  -0.0%

  [ = ]       0 TOTAL                                      0  [ = ]


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

libgrpc++.so

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

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link

[trickle] No significant performance differences

@grpc-testing
Copy link

[microbenchmarks] No significant performance differences

Copy link
Member

@nathanielmanistaatgoogle nathanielmanistaatgoogle left a comment

Choose a reason for hiding this comment

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

🎉🎉🎉🎉🎉

@kpayson64 kpayson64 merged commit c394965 into grpc:master Mar 28, 2018
@kpayson64
Copy link
Contributor Author

#14815

@jtattermusch
Copy link
Contributor

jtattermusch commented Apr 4, 2018

@kpayson64 , are you aware that this PR disables python dbg tests entirely for all of linux, mac and windows? I don't think we want that.

https://github.com/grpc/grpc/pull/14561/files#diff-38ce68e55e10fc655a0123717db8498dR199

@yaalaa
Copy link

yaalaa commented Apr 14, 2018

kernel: [ 735.355126] gunicorn[6538]: segfault at 30 ip 00007f17641970ca sp 00007ffe919a8bf0 error 4 in cygrpc.so[7f17640fb000+326000]

Google App Engine Flexible VM. grpc v1.11.0.

@kpayson64
Copy link
Contributor Author

@jtattermusch
That was deliberate, Python builds have never respected the dbg option (they still build in opt mode), and I wanted to avoid doubling the number of tests run when adding this feature.

Running with -c dbg outputs the following:

tools/run_tests/run_tests.py -l python --compiler=python2.7 -c dbg --build_only

[1/1] Cythonizing src/python/grpcio/grpc/_cython/cygrpc.pyx
running build_ext
Found cython-generated files...
building 'grpc._cython.cygrpc' extension
ccache gcc -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -I/usr/local/google/home/kpayson/grpc/include -std=gnu99 -fno-wrapv -fPIC -DOPENSSL_NO_ASM=1 -D_WIN32_WINNT=1536 -DGPR_BACKWARDS_COMPATIBILITY_MODE=1 -DHAVE_CONFIG_H=1 -DGRPC_ENABLE_FORK_SUPPORT=1 -DPyMODINIT_FUNC=__attribute__((visibility ("default"))) void -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1 -Isrc/python/grpcio -Iinclude -I. -Ithird_party/boringssl/include -Ithird_party/zlib -Ithird_party/cares -Ithird_party/cares/cares -Ithird_party/cares/config_linux -I/usr/include/python2.7 -c src/python/grpcio/grpc/_cython/cygrpc.c -o python_build/temp.linux-x86_64-2.7/src/python/grpcio/grpc/_cython/cygrpc.o -std=c++11 -std=gnu99 -fvisibility=hidden -fno-wrapv -fno-exceptions -DPB_FIELD_16BIT -pthread
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C

The Python build system automatically inserts the NDEBUG define. If we want to start running Python debug tests, we will have to figure out how to get around this.

@kpayson64
Copy link
Contributor Author

kpayson64 commented Apr 15, 2018

@yaalaa
Can you open a new issue with detailed reproduction steps and a core dump at the crash?

@yaalaa
Copy link

yaalaa commented Apr 15, 2018

I could try to describe how I've ended up in crash. As to core dump, I'm not sure I can get it from GAE VM.
Just few words here:

  • it's gunicorn+gevent+google-cloud (grpc) trio
  • I've inserted patch suggested at the top of this issue into post_fork gunicorn callback and patch run ok (I see log right after that)
  • gunicorn worker segfaults nearly after creation (post_worker_init has fired)

@yaalaa
Copy link

yaalaa commented Apr 15, 2018

@kpayson64
Here you are: #15071
It's not exactly what you requested but something of the kind.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 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.

None yet

9 participants