Profiling, bottleneck analysis, database optimization, CDN, scaling strategies
Оптимизация Django приложений для highload.
💡 Правило: Измеряйте перед оптимизацией, оптимизируйте узкие места.
# django-silk
pip install django-silk
# /silk/ endpoint показывает profiling запросов
# cProfile
python -m cProfile -o output.prof manage.py runserver
snakeviz output.prof # Визуализация# N+1 решение
Post.objects.select_related('author').prefetch_related('tags')
# Индексы
class Meta:
indexes = [
Index(fields=['-created_at']),
Index(fields=['author', '-created_at']),
]
# Explain
queryset.explain(analyze=True)# Per-view
@cache_page(60 * 15)
def my_view(request):
...
# Fragment
{% cache 500 sidebar user.id %}
...
{% endcache %}
# Low-level
cache.set('key', value, 300)
data = cache.get('key')# settings.py
STATIC_URL = 'https://cdn.example.com/static/'
# django-storages + S3 + CloudFrontВопросы ещё не добавлены
Вопросы для этой подтемы ещё не добавлены.