Azure / Azure/azure-sdk-for-python

High CPU usage (100%) when awaiting begin_analyze_document inside Docker/Kubernetes

オープン
#44,449 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
customer-reported Document Intelligence needs-team-attention question Service Attention
主要言語
Python
スター
5.6k
フォーク
3.4k
平均マージ
2日 2時間
マージ済み PR(30日)
213

説明

---

* **Package Name**: `azure-ai-documentintelligence`
* **Package Version**: `1.0.2`
* **Operating System**: Linux (Docker container, Kubernetes environment)
* **Python Version**: Python 3.x

---

### **Describe the bug**

When using `azure-ai-documentintelligence` inside a Docker container, the application consistently consumes 100% CPU during document analysis.
This occurs even when the container is explicitly constrained to **1 CPU core and 2 GB of memory**.

When deployed in Kubernetes, this behavior causes pods to be terminated with **OOMKill** once CPU usage reaches 100%, despite the simplicity of the workload.

The issue occurs while awaiting the result of `begin_analyze_document`, specifically during `await poller.result()`.

---

### **To Reproduce**

Steps to reproduce the behavior:

1. Build an API using **FastAPI**
2. Build the Docker image:

```bash
docker build -t document-intelligence-test .
```

3. Run the container with explicit CPU and memory limits:

```bash
docker run --cpus="1.0" -m 2g --memory-swap 2g document-intelligence-test
```

4. Monitor resource usage using:

```bash
docker stats
```

5. Execute the following code inside the container:

```python
from azure.ai.documentintelligence import DocumentIntelligenceClient
from azure.core.credentials import AzureKeyCredential
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest

client = DocumentIntelligenceClient(
endpoint="",
credential=AzureKeyCredential("")
)

analyze_request = AnalyzeDocumentRequest(
url_source="https://www.kinea.com.br/wp-content/uploads/2025/05/KNCR_Regulamento_05-2025.pdf"
)

poller = client.begin_analyze_document(
body=analyze_request,
model_id="prebuilt-layout",
output_content_format="markdown"
)

result = await poller.result()
```

---

### **Expected behavior**

CPU usage should remain within reasonable limits while waiting for the document analysis to complete.
The SDK should not fully saturate the allocated CPU core during asynchronous polling.

---
### **Screenshots**

Image

Image

Image

---

### **Additional context**

* Reproducible with a single request and no concurrency
* Occurs consistently inside Docker containers
* Happens even with strict resource limits (`--cpus="1.0"`, `-m 2g`, `--memory-swap 2g`)
* In Kubernetes environments, this behavior results in **OOMKill**
* No custom threading, multiprocessing, or manual polling logic is implemented
* Behavior suggests a possible inefficient or busy-wait polling loop inside the SDK

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、提供された Docker の制限内で azure-ai-documentintelligence 1.0.2 を使用した単一リクエストの例を再現し、その後 begin_analyze_document と await poller.result() の周辺で CPU 使用率を観察します。SDK の非同期ポーリングパスを調査し、ビジーウェイト動作がないか確認します。制約された CPU を飽和させたり Kubernetes OOMKill を引き起こしたりせずにドキュメント分析が完了すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
azure, docker, fastapi, kubernetes, python
領域
backend, cloud, devops, performance
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。