我们如何开始我们的 async python 迁移

This article describes how Duolingo migrated its first synchronous (sync) Python microservice to asynchronous (async) Python.

本文介绍了 Duolingo 如何将其第一个同步(sync)Python 微服务迁移到异步(async)Python。

The structure of this article follows questions we needed to answer as the project progressed:

本文的结构遵循我们在项目推进过程中需要回答的问题:

  • How do we build consensus to try the migration?
  • 我们如何建立共识来尝试迁移?
  • How do we architect async versions of sync libraries?
  • 我们如何为同步库设计异步版本?
  • How do we structure async code?
  • 我们如何组织异步代码?

Should you try async?

你应该尝试 async 吗?

Before diving into the migration itself, I’d like to share some unfortunate realities of an async Python migration and some background on why we tried it.

在深入迁移本身之前,我想先分享一些关于异步 Python 迁移的不幸现实,以及我们当初尝试它的背景。

Supporting async Python, or allowing developers to write async Python microservice code, is about as hard as supporting a new programming language. We had to reconsider almost every aspect of our service design to support async Python. This included but was not limited to:

支持异步 Python,或让开发者能够编写异步 Python 微服务代码,其难度几乎等同于支持一门全新的编程语言。为了支持异步 Python,我们不得不重新思考服务设计的几乎每一个方面,包括但不限于:

  • Rewriting our HTTP clients
  • 重写我们的 HTTP 客户端
  • Rewriting our auth clients
  • 重写我们的 auth 客户端
  • Reintegrating observability tooling
  • 重新集成可观测性工具
  • Rearchitecting our Python backends
  • 重新架构我们的 Python 后端
  • Adding async APIs to in-house tools
  • 为内部工具添加异步 API

Supporting async Python is difficult; however, migrating a service from sync to async Python is fairly straightforward once support is in place. At Duolingo, we have a lot of sync Python service code. Async Python provides a significant performance benefit for services (we measured that an async service can handle 40% more requests per instance than its sync counterpart), at a lower cost of migration than rewriting that service in a more performant language like Go**.**

支持异步 Python 很困难;然而,一旦支持到位,将服务从同步 Python 迁移到异步 Python 就相对简单。在 Duolingo,我们拥有大量同步 Python 服务代码。异步 Python 为服务带来了显著的性能提升(我们测得异步服务单实例可处理的请求量比同步版本高 40%),且迁移成本远低于用 Go 等更高性能语言重写服务。

There are many reasons to perform an async Python migration, but service ...

开通本站会员,查看完整译文。

- 위키
Copyright © 2011-2025 iteam. Current version is 2.146.0. UTC+08:00, 2025-10-20 17:01
浙ICP备14020137号-1 $방문자$