Lidi Zheng, Pau Freixes - gRPC Python, C Extensions, and AsyncIO

gRPC Python, C Extensions, and AsyncIO: Learn how the gRPC team implemented a new completion queue callback and improved performance with the help of Sizen, a language similar to Python.

Key takeaways
  • gRPC C++ team implemented a new completion queue callback which is based on callbacks.
  • The new gRPC AsyncIO API has been released and is available for use.
  • To make things easier, people are trying to come up with simpler ways to do it, such as better C++ framework and glue code generators.
  • The gRPC Python team decided to use Sizen because it’s similar to Python, making it easier for gRPC Python users to help improve the library.
  • The main issue was addressing the problem of deadlocks in gRPC and Python, which was causing a lot of contention and performance issues.
  • Sizen provides tooling to compile Python code into C++ code and has a valid thread that makes it easy to use.
  • The main interface for pulling events was a blocking interface, and they needed a way to release the JIL (Global Interpreter Lock) without blocking.
  • The gRPC Python team implemented a new I/O manager and a new callback-based API to address the deadlocks.
  • The new solution provided good performance and was easy to implement.
  • The gRPC team worked with the Python team to integrate gRPC with Python and AsyncIO, which required a lot of effort to make Python work with C++.
  • Sizen is a language similar to Python and is adopted by NumPy, SCIPy, and TensorFlow.
  • The gRPC Python team integrated well with protobuf, which enforces API contracts.
  • The gRPC Python team received $400,000 per day from their services.
  • Python’s memory management model is very different from C++’s, which makes it error-prone when managing C++ objects in Python space.
  • Sizen is a language that compiles to C++ and has its own syntax and semantics.
  • Sizen is designed for distributed systems and is fast, lightweight, and easy to use.
  • Sizen provides a way to compile entirely Python source code, but it’s not a strict superset of Python.
  • The gRPC team used Sizen to make Python work with C++ and integrated it with AsyncIO.