最佳化基於 Python 的開源無服務器 API 性能
Optimizing Python-based Open-Sourced Serverless API Performance
摘要
Serverless 平臺提供以 Container 或 microVM 為基礎的 FaaS 服務,相較傳統基於 VM 為主的 IaaS 具備更小的開發粒度、彈性的資源配置、近乎零維運成本、按使用量計費、快速更新部署等諸多優點,逐漸成為現代重要的雲端運算模型。相較於公有雲雲端服務供應商所提供的閉源 Serverless 平臺,開源的 Serverless 平臺具有可以在任意基礎設施、雲端平臺部署的優勢,避免被單一雲端供應商綁定 (Vendor lock-in)。
然而現有的開源 Serverless 平臺在執行 Python 語言的函式時,大多基於 Flask 去建構 function runtime,而Flask 是基於 Python 實作為主的 Werkzeug WSGI utility library 進行開發,因此在高吞吐 HTTP 處理路徑上仍存在很大的性能改進空間。一些開源的 HTTP toolkit 如 Japronto 透過 Python C extension、使用 SIMD 指令解析 HTTP header,以及採用性能更好的 event loop 實作(例如 uvloop)等方法進一步加速 Python 在處理 HTTP 請求的能力。
我們的工作是以開源專案 uvloop/Japronto/asyncpg 作為基礎,透過一系列方法進一步去改進上述開源工具的性能,使其在本研究採用的 TFB 工作負載與實驗環境下達到目前比較對象中的最高吞吐表現。在處理靜態請求方面我們的改進方法相比於原始的 Japronto 在 Plaintext with HTTP pipelining 場景提升 68.26%。在動態請求 Single database query 方面提升 79.15%。
然而現有的開源 Serverless 平臺在執行 Python 語言的函式時,大多基於 Flask 去建構 function runtime,而Flask 是基於 Python 實作為主的 Werkzeug WSGI utility library 進行開發,因此在高吞吐 HTTP 處理路徑上仍存在很大的性能改進空間。一些開源的 HTTP toolkit 如 Japronto 透過 Python C extension、使用 SIMD 指令解析 HTTP header,以及採用性能更好的 event loop 實作(例如 uvloop)等方法進一步加速 Python 在處理 HTTP 請求的能力。
我們的工作是以開源專案 uvloop/Japronto/asyncpg 作為基礎,透過一系列方法進一步去改進上述開源工具的性能,使其在本研究採用的 TFB 工作負載與實驗環境下達到目前比較對象中的最高吞吐表現。在處理靜態請求方面我們的改進方法相比於原始的 Japronto 在 Plaintext with HTTP pipelining 場景提升 68.26%。在動態請求 Single database query 方面提升 79.15%。
Serverless platforms provide Function-as-a-Service (FaaS) offerings based on containers or microVMs. Compared to traditional VM-based Infrastructure-as-a-Service (IaaS) platforms, serverless solutions offer finer development granularity, elastic resource allocation, near-zero operational costs, pay-as-you-go pricing, and rapid deployment, making them a critical component of modern cloud computing. Open-source serverless platforms, in contrast to proprietary alternatives provided by public cloud vendors, offer the flexibility to deploy on any infrastructure, mitigating vendor lock-in issues.
However, existing open-source serverless platforms often rely on Flask for Python function runtimes, which is built on the Werkzeug WSGI library, a Python-centric WSGI utility library implemented primarily in Python that presents significant opportunities for performance improvement on high-throughput HTTP request paths. Recent open-source HTTP toolkits, such as Japronto, leverage Python C extensions, SIMD instructions for HTTP header parsing, and more efficient event loop implementations (e.g., uvloop) to enhance Python's HTTP request-handling capabilities further.
This research is based on open-source tools like uvloop, Japronto, and asyncpg. Through a series of optimizations, we aim to significantly improve the performance of a Python function runtime built on top of these tools, ultimately delivering one of the most efficient Python function runtimes among the open-source serverless baselines evaluated in this study. Our optimization methods achieve a 68.26% throughput improvement over the original Japronto baseline in handling static requests in the Plaintext with HTTP pipelining scenario, and a 79.15% throughput improvement in dynamic single database query requests.
However, existing open-source serverless platforms often rely on Flask for Python function runtimes, which is built on the Werkzeug WSGI library, a Python-centric WSGI utility library implemented primarily in Python that presents significant opportunities for performance improvement on high-throughput HTTP request paths. Recent open-source HTTP toolkits, such as Japronto, leverage Python C extensions, SIMD instructions for HTTP header parsing, and more efficient event loop implementations (e.g., uvloop) to enhance Python's HTTP request-handling capabilities further.
This research is based on open-source tools like uvloop, Japronto, and asyncpg. Through a series of optimizations, we aim to significantly improve the performance of a Python function runtime built on top of these tools, ultimately delivering one of the most efficient Python function runtimes among the open-source serverless baselines evaluated in this study. Our optimization methods achieve a 68.26% throughput improvement over the original Japronto baseline in handling static requests in the Plaintext with HTTP pipelining scenario, and a 79.15% throughput improvement in dynamic single database query requests.