gRPC Python, C Extensions, and AsyncIO

How to make AsyncIO work with the gRPC Core

Lidi Zheng, Pau Freixes

ASYNC / Concurreny CPython Cython Performance

See in schedule Download/View Slides

Goal - Encourage Python developers to understand C extensions by sharing gRPC Python’s practice, and advocate the adoption of AsyncIO.

- Understand thread vs. process;
- Interested in asynchronous programming.

gRPC Brief
- What’s gRPC Core? And what is gRPC Python?

Cython To The Rescue
- Why we picked Cython among all other available tools (e.g., pybind11, ctypes)
- Debuggability: pdb & gdb

The GIL Friction
- How to delegate work to C extension
- How to make multithreading work

AsyncIO Topic
- Not blocking the loop, the main headache.
- Non-blocking I/O solution 1: replacing C libraries’ I/O operations
- Non-blocking I/O solution 2: dedicated background poller thread
- Performance improvement (10k -> 20k for client, 4k -> 16k for server)

Migration to AsyncIO
- Tolerate multithreading and AsyncIO in the same application
- Make both API co-existable in the same application

Type: Talk (30 mins); Python level: Intermediate; Domain level: Intermediate

Lidi Zheng


Lidi Zheng is a Software Engineer at Google under the Tech Infra Network Systems area. He is an active maintainer of gRPC repo, and mostly contributing to gRPC Python. He focuses on the API design, distributed system and tooling. Prior to Google, he completed his Master degree from CMU in 2018, and had several years of experience in technology startups in Beijing.

Pau Freixes


Ive been working for the last 4 years as a Software Engineer at Skyscanner, during all of this time I had the chance to build, run and own many Python services at scale in production, mainly based on Asyncio. This gave me a privileged situation for contributing to the open-source community by making different contributions to projects like aiohttp, aioredis and most recently to gRPC.