Django Profiler和实际http响应之间的巨大时差

时间:2018-10-15 18:09:21

标签: django docker nginx django-rest-framework django-silk

我正在使用django-rest-framework构建RESTful API。我遇到一些响应延迟问题,因此我决定使用silk库来分析视图的响应。这是视图的代码:

Menu.Item

提出请求后,我得到了以下结果:

Silk profilling result

Postman timmings

这相差近50倍!

有人可以帮助我找到并解决这种差异吗?

class ChecklistDetail(APIView): permission_classes = (permissions.IsAuthenticated, StaffPermission) @silk_profile(name='get ChecklistDetail') def get(self, request, pk, format=None): # pylint: disable=E1101 checklist = Checklist.objects.get(pk=pk) serializer = ChecklistSerializer(checklist, many=False) return Response(serializer.data) 类是:

StaffPermission

我的nginx配置:

class StaffPermission(permissions.BasePermission):
    message = 'Only active staff can perform unsafe methods.'

    def has_permission(self, request, view):
        if request.method in permissions.SAFE_METHODS:
            return request.user.is_authenticated and request.user.is_active
        else:
            return request.user.is_staff and request.user.is_active

我的gunicorn命令:

upstream atlas-intelligence-server {
  ip_hash;
  server atlas-intelligence-server:80;
}

# portal
server {
  location / {
        proxy_pass http://atlas-intelligence-server/;
  }
  listen 80;
  client_max_body_size 100M;
  server_name localhost;

  # Avoid 504 HTTP Timeout Errors
  proxy_connect_timeout       605;
  proxy_send_timeout          605;
  proxy_read_timeout          605;
  send_timeout                605;
  keepalive_timeout           605;
}

nginx(gunicorn atlas_intelligence.wsgi -b 0.0.0.0:80 --workers 2 --log-level debug --error-logfile /var/log/gunicorn_err.log --log-file /var/log/gunicorn.log --timeout 300 )和django机器都是容器。

0 个答案:

没有答案