Azure / Azure/azure-sdk-for-python
High CPU usage (100%) when awaiting begin_analyze_document inside Docker/Kubernetes
- Vorherrschende Sprache
- Python
- Sterne
- 5.6k
- Forks
- 3.4k
- Ø Merge
- 2 T. 2 Std.
- Gemergte PRs (30 T.)
- 202
Beschreibung
---
* **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**
---
### **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
Beitragsleitfaden
Rechercherichtung
Beginne damit, das Beispiel für eine einzelne Anfrage mit azure-ai-documentintelligence 1.0.2 innerhalb der vorgegebenen Docker-Limits zu reproduzieren, und beobachte dann die CPU-Auslastung rund um begin_analyze_document und await poller.result(). Untersuche den asynchronen Polling-Pfad des SDK auf Busy-Wait-Verhalten. Als erledigt gilt die Aufgabe, wenn die Dokumentanalyse abgeschlossen wird, ohne die begrenzte CPU vollständig auszulasten oder einen Kubernetes OOMKill zu verursachen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- azure, docker, fastapi, kubernetes, python
- Bereich
- backend, cloud, devops, performance
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100