title: Django + Gunicorn + nginx yields very poor performance. Can't get even 8 qps
body: <p>I am using nginx + gunicorn for serving a django app and have deployed it on EC2 (m1.small instance).</p>
  
  <p>I have this view:</p>
  
  <pre><code>def hi(request):
      return HttpResponse('hi', content_type='text/plain')
  </code></pre>
  
  <p>mapped to url <code>/hi/</code>. So it basically just returns <code>hi</code> at <code>[myurl]/hi</code>.</p>
  
  <p>Now when I load test this domain (<code>[myurl]/hi</code>) from <code>loader.io</code>, this doesn't even pass the <strong>250 clients over 30 secs</strong> test. (Approx 8 requests per second)</p>
  
  <p><a href="http://pastebin.com/JZ6iNF7K" rel="noreferrer">This is</a> (part of) my nginx access.log file. It basically just gives <code>499</code>s after few <code>200</code>s. (Timeout in loader.io is set to 10 secs)</p>
  
  <p>I must be doing something seriously wrong. How do I find out?</p>
  
  <p>I profiled it using <code>yet-another-django-profiler</code> and following is the output:
  <img src="https://i.stack.imgur.com/NY5rc.png" alt="enter image description here"></p>
  
  <p>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:</p>
  
  <pre><code>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',
  )
  </code></pre>
  
  <p>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. </p>