How do you profile a slow Django application in production (Silk, APM tools, logging slow queries)? प्रोडक्शन में एक धीमे Django एप्लिकेशन को कैसे प्रोफाइल करें (Silk, APM टूल्स, धीमी क्वेरीज़ लॉग करना)?
Django Debug Toolbar only works in development against a single request at a time; production profiling needs tools that run safely under real traffic with minimal overhead. Django Silk is a lightweight profiler that can run in production (with sampling) to record request timings and SQL queries into a database, browsable later through a UI, without requiring a live debugging session.
Application Performance Monitoring (APM) tools like Sentry, New Relic, or Datadog APM instrument the whole application automatically, capturing slow request traces, database query timing, external call latency, and error rates across all instances, with alerting when performance degrades. For database-specific slowness, most database engines also support logging queries that exceed a duration threshold (e.g. PostgreSQL's log_min_duration_statement), which surfaces slow queries directly from the source of truth regardless of which Django code path triggered them.
LOGGING = {
'version': 1,
'handlers': {'console': {'class': 'logging.StreamHandler'}},
'loggers': {
'django.db.backends': {
'handlers': ['console'],
'level': 'DEBUG',
},
},
}Django Debug Toolbar केवल डेवलपमेंट में एक समय में एक रिक्वेस्ट के विरुद्ध काम करता है; प्रोडक्शन प्रोफाइलिंग के लिए ऐसे टूल्स चाहिए जो वास्तविक ट्रैफिक के तहत न्यूनतम ओवरहेड के साथ सुरक्षित रूप से चलें। Django Silk एक हल्का प्रोफाइलर है जो प्रोडक्शन में चल सकता है।
Sentry, New Relic, या Datadog APM जैसे Application Performance Monitoring टूल्स पूरे एप्लिकेशन को स्वचालित रूप से इंस्ट्रूमेंट करते हैं।
LOGGING = {
'version': 1,
'handlers': {'console': {'class': 'logging.StreamHandler'}},
'loggers': {'django.db.backends': {'handlers': ['console'], 'level': 'DEBUG'}},
}Was this answer clear?