我的Django实例在ubuntu 16.04.2 LTS之上的EC2上运行。我的api响应非常慢,在调试过程中,我发现几乎所有的内存都被利用了。
以下是屏幕截图供您参考:
ubuntu@ip-xxx-31-22-205:~/Django/user$ free -m
total used free shared buff/cache available
Mem: 990 860 69 10 60 14
Swap: 0 0 0
Top命令对内存利用率并没有多说。这是ps -aux命令的输出
ubuntu@ip-xxx-31-22-205:~/django/user$ ps aux --sort=-%mem | awk 'NR<=10{print $0}'
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 8102 0.1 5.8 311428 59216 ? Sl 05:28 0:03 /home/ubuntu/django/user/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 8108 0.0 5.7 239012 58356 ? S 05:31 0:01 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 7254 0.0 5.7 239728 58200 ? S May03 0:01 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 5590 0.0 5.6 239440 57632 ? S May02 0:03 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 6929 0.0 5.6 251536 57340 ? Sl May03 0:02 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 2039 0.0 5.5 179196 56324 ? S 2018 2:08 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14416 0.0 5.5 167712 56096 ? S 2018 1:55 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14461 0.0 5.4 243860 55772 ? S 2018 1:55 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 13520 0.0 4.5 212172 45860 ? S Jan17 1:18 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
这是ps -ef命令的输出:
ubuntu@ip-xxx-31-22-205:~$ ps -ef | grep gunicorn
root 2032 1 0 2018 ? 00:27:04 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 2037 2032 0 2018 ? 00:02:14 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 2039 2032 0 2018 ? 00:02:08 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 2111 1 0 2018 ? 00:27:08 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 2186 1 0 2018 ? 00:27:19 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 5585 1 0 May02 ? 00:00:20 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 5590 5585 0 May02 ? 00:00:03 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 5592 5585 0 May02 ? 00:00:01 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 6382 1 0 May03 ? 00:00:15 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 6929 6382 0 May03 ? 00:00:02 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 7254 6382 0 May03 ? 00:00:01 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 7273 14410 0 May03 ? 00:00:01 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 7276 2111 0 May03 ? 00:00:01 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 7296 1 0 May03 ? 00:00:12 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 7304 6382 0 May03 ? 00:00:01 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 7318 5585 0 May03 ? 00:00:01 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 8102 7296 0 05:28 ? 00:00:02 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 8108 7296 0 05:31 ? 00:00:01 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 8111 7296 0 05:32 ? 00:00:00 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
ubuntu 8189 8168 0 05:48 pts/2 00:00:00 grep --color=auto gunicorn
root 9546 14454 0 Jan13 ? 00:01:24 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 13519 14472 0 Jan17 ? 00:01:20 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 13520 14472 0 Jan17 ? 00:01:18 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 13742 2111 0 Jan17 ? 00:01:19 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14410 1 0 2018 ? 00:24:51 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14416 14410 0 2018 ? 00:01:55 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14454 1 0 2018 ? 00:24:58 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14461 14454 0 2018 ? 00:01:55 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14472 1 0 2018 ? 00:25:02 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14476 2186 0 2018 ? 00:01:56 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14483 2186 0 2018 ? 00:01:54 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 14541 2111 0 2018 ? 00:01:55 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 24952 14454 0 Jan28 ? 00:01:08 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 24953 2032 0 Jan28 ? 00:01:10 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 24955 14410 0 Jan28 ? 00:01:11 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 24956 14472 0 Jan28 ? 00:01:11 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
root 24957 2186 0 Jan28 ? 00:01:09 /home/ubuntu/django/viago/venv/bin/python3 /home/ubuntu/django/viago/venv/bin/gunicorn config.wsgi:application -w 3 --bind=unix:/home/ubuntu/django/viago/gunicorn.sock --preload --log-level=debug --log-file=/home/ubuntu/django/viago/gunicorn.log
我从这里了解到,在后台运行着多个gunicorn实例。 我创建了一个脚本start_gunicorn.sh来启动gunicorn实例。据我了解,我只能启动实例,但是此脚本无法重启或停止实例。我在这里有两个问题:
gunicorn的多个实例是否导致更高的内存消耗?如果我杀死所有的pid并启动gunicorn脚本,那会有所帮助并且安全吗?
重新启动和/或停止gunicorn实例的方式是什么?