Files
voidea/docs/performance.md
T

50 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Производительность
## Performance budgets (p95)
| Метрика | Лимит | Примечание |
|---------|-------|------------|
| API response (без AI) | < 500ms | |
| API response (с AI) | < 5s | Fallback после таймаута |
| DB query (одиночный) | < 100ms | С индексом |
| WebUI page load | < 2s | |
| AI call | < 5s | Иначе fallback |
## Индексы БД
```sql
CREATE INDEX ix_ideas_user_id ON ideas(user_id);
CREATE INDEX ix_ideas_status ON ideas(status);
CREATE INDEX ix_ideas_created_at ON ideas(created_at);
CREATE INDEX ix_users_email ON users(email);
```
## Connection pool
```python
engine = create_async_engine(
settings.database_url,
pool_size=10,
max_overflow=20,
pool_pre_ping=True,
)
```
## Метрики
| Метрика | Тип | Описание |
|---------|-----|----------|
| `http_requests_total` | Counter | Всего запросов |
| `http_request_duration_ms` | Histogram | Время ответа (p50/p95/p99) |
| `http_errors_total` | Counter | 4xx и 5xx |
| `ai_provider_calls` | Counter | Вызовы AI провайдеров |
| `agent_execution_duration` | Histogram | Время выполнения агентов |
**Где хранить:** в БД (таблица `agent_metrics`), в перспективе — Prometheus.
## Когда оптимизировать
1. Профилировать до оптимизации. Не гадать — измерять.
2. Оптимизировать только горячие пути (90% времени на 10% кода).
3. Кэшировать только то, что реально часто читается.