Azure / Azure/azure-sdk-for-python
High CPU usage (100%) when awaiting begin_analyze_document inside Docker/Kubernetes
- Lingua principale
- Python
- Stelle
- 5.6k
- Fork
- 3.4k
- Merge medio
- 2g 2h
- PR unite (30g)
- 202
Descrizione
---
* **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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia riproducendo l’esempio di una singola richiesta con azure-ai-documentintelligence 1.0.2 entro i limiti Docker forniti, quindi osserva l’utilizzo della CPU intorno a begin_analyze_document e await poller.result(). Ispeziona il percorso di polling asincrono dell’SDK per verificare la presenza di un comportamento di busy-wait. Il lavoro è completato quando l’analisi del documento termina senza saturare la CPU limitata né causare un Kubernetes OOMKill.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- azure, docker, fastapi, kubernetes, python
- Ambito
- backend, cloud, devops, performance
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100