I am using nginx + gunicorn for serving a django app and have deployed it on EC2 (m1.small instance).
I have this view:
def hi(request):
return HttpResponse('hi', content_type='text/plain')
mapped to url /hi/
. So it basically just returns hi
at [myurl]/hi
.
Now when I load test this domain ([myurl]/hi
) from loader.io
, this doesn't even pass the 250 clients over 30 secs test. (Approx 8 requests per second)
This is (part of) my nginx access.log file. It basically just gives 499
s after few 200
s. (Timeout in loader.io is set to 10 secs)
I must be doing something seriously wrong. How do I find out?
I profiled it using yet-another-django-profiler
and following is the output:
I deployed this django app on Elastic Beanstalk (which uses Apache server) too (m3.large instance), and there too I get terrible performance. My middleware as of now is:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
# 'silk.middleware.SilkyMiddleware',
# 'yet_another_django_profiler.middleware.ProfilerMiddleware',
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
# 'django.contrib.messages.middleware.MessageMiddleware',
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
# 'django.middleware.security.SecurityMiddleware',
)
Earlier none of it was commented out. When I commented out these 9 lines, I got a performance boost. Now I can get 60 qps out of this app. But I think I am doing more blunders and that it can scale further.
This is just a stab in the dark without more to go on, and I don't have enought reputation to comment on your original question: I noticed that your gunicorn startup script has
--log-level=debug
If you have debug level logging (in gunicorn and especially in the Django project) it would explain why the performance was increased by commenting out the middleware and why you would keep getting degraded performance out of a different deployment architecture.
Debug level logging outputs A LOT of information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With