首页 > 解决方案 > Django Apache 和 Elastic Beanstalk 的 API 响应时间很慢

问题描述

我在 django 中有一个 POST API,并且我已经为应用程序安装了 New Relic APM。django 处理请求所需的时间约为 250 毫秒,但响应时间(从邮递员测量)约为 2.5 秒。

我的架构设置在 AWS Elastic Beanstalk 上。

  1. 负载均衡器(使用 SSL)用作 Web 界面

  2. 一个 Linux 实例通过 WSGI 与 Django 应用程序一起运行 Apache

连续请求的响应时间从 2.5 秒到 600 毫秒不等。如何识别问题并将响应时间缩短到 500 毫秒以下

这是我用于 http.d 的 wsgi.conf

LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/python/run/baselinenv
WSGISocketPrefix run/wsgi
WSGIRestrictEmbedded On

<VirtualHost *:80>

Alias /static/ /opt/python/current/app/static/
<Directory /opt/python/current/app/static/>
Order allow,deny
Allow from all
</Directory>


WSGIScriptAlias / /opt/python/current/app/test_proj/wsgi.py
WSGIPassAuthorization On
WSGIPassAuthorization On
WSGIPassAuthorization On


<Directory /opt/python/current/app/>
  Require all granted
</Directory>

WSGIDaemonProcess wsgi processes=1 threads=15 display-name=%{GROUP} \
  python-home=/opt/python/run/venv/ \
  python-path=/opt/python/current/app:/opt/python/run/venv/lib64/python3.6/site-packages:/opt/python/run/venv/lib/python3.6/site-packages user=wsgi group=wsgi \
  home=/opt/python/current/app
WSGIProcessGroup wsgi
</VirtualHost>

LogFormat "%h (%{X-Forwarded-For}i) %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

新遗物统计

邮递员响应时间

标签: djangoapacheoptimizationamazon-elastic-beanstalkmod-wsgi

解决方案


推荐阅读