title: Understanding slow Django performance
body: <p>My webserver is scaling and I'm using Sentry Performance to try and better understand where things are slow. One thing that I don't quite understand is where the slowness might be coming from when the total reported query times are dramatically different than the time it takes to get a response.</p>
  <p>For example, one of my endpoints is taking 40s to finally get a response to the user. You'll see the total response time took an incredible 44,000ms even though all the work was done in about 1s (which is still slow, but not 44s slow).</p>
  <p>Edit: as a general note, all of my endpoints are doing this– the peculiar thing is those dashed dots at the end of the timeline where any of the actual Django / database hits begin. It just sits blank for a whole minute before Django begins doing anything. Is this a potential guincorn or Uvicorn configuration error?</p>
  <p>Additional info:</p>
  <ul>
  <li>Running gunicorn w/ uvicorn: <code>poetry run gunicorn -w 17 myApp.asgi:application -k myApp.uvicorn.AppUvicornWorker --log-level=debug</code></li>
  <li>I'm getting about a hundred requests a second, which the server should be more than able to handle– it has 32gb of ram and 8 cpu cores.</li>
  </ul>
  <p>AppUvicornWorker:</p>
  <pre><code>class AppUvicornWorker(UvicornWorker):
      CONFIG_KWARGS = {&quot;loop&quot;: &quot;uvloop&quot;, &quot;http&quot;: &quot;httptools&quot;, &quot;lifespan&quot;: &quot;off&quot;}
  </code></pre>
  <ul>
  <li>Views are just basic, completely standard Django Rest Framework ListViewSets queried:</li>
  </ul>
  <pre><code>class UserSerializer(serializer.ModelSerializer):
      class Meta:
          model = User
          fields = [&quot;id&quot;, &quot;username&quot;, &quot;name&quot;]
  
  class CommentSerializer(serializer.ModelSerializer):
      user = UserSerializer()
  
      class Meta:
          model = Comment
          fields = [&quot;id&quot;, &quot;text&quot;, &quot;user&quot;]
  
  
  class CommentsViewSet(viewsets.ViewSet):
      def list(self, request):
          queryset = Comments.objects.all()
          serializer = CommentSerializer(queryset, many=True)
          return Response(serializer.data)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/vd0qg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vd0qg.png" alt="enter image description here" /></a></p>