【发布时间】:2017-12-19 01:44:43
【问题描述】:
我在 Ubuntu 16.04 上使用 Postgres、Nginx 和 Gunicorn 在 Digital Ocean(512MB 内存)中有 django 应用程序。在运行应用程序时,它会消耗更多内存。如果我浏览页面,它也会在使用 top 命令检查时消耗内存。会出现什么问题,可能的原因是什么。
独角兽
[Unit]
Description=veeyar daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/webapps/myproject/
ExecStart=/home/webapps/myproject/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/webapps/myproject/myproject.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
Nginx
server {
listen 9090;
location = /favicon.ico { access_log off; log_not_found off; }
location ^/static/ {
root /home/webapps/myproject/staticfiles;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/webapps/myproject/myproject.sock;
}
}
并且在 settings.py 中我设置了 DEBUG=False。
我尝试通过谷歌搜索,但我无法正确理解。为什么会这样,我错过了什么。你们能帮我解决这个问题吗?这对我来说将是非常充分的。提前致谢。
【问题讨论】:
-
您的设置看起来还不错,您是否执行任何长时间运行/计算任务?
-
@OrDuan 感谢您的回复。不,我没有任何长时间运行/计算的任务。但是有更多来自不同表的近 14000 行记录。
-
你有内存泄漏,没有代码很难说哪里。检查您是否更改了在调用中持续存在的变量,因为它们是全局变量或导入变量。
-
@KlausD。感谢您的答复。从某种意义上说内存泄漏,我可以在我的代码中解决这个问题吗?
-
造成内存泄漏的方法太多,这里就不一一解释了。对不起。
标签: python django memory server