장고에 Geoip2()에 "[errno를 12] 메모리를 할당 할 수 없습니다"다음 코드는 <code>manage.py shell</code>에서 성공적으로 실행 uWSGI
from django.contrib.gis.geoip2 import GeoIP2
g = GeoIP2()
내가 manage.py runserver
수동으로 서버를 시작하는 경우와의 코드를 넣어 내 장고보기, 그것도 잘 실행됩니다.
내 장고 응용 프로그램은 uWSGI
및 Nginx
역방향 프록시 호스팅됩니다. 모두 uWSGI
및 www-data
사용자와의 Nginx
실행됩니다.
...
File "/home/myuser/Env/virtenv/myproject/index/views.py" in index
28. g = GeoIP2()
File "/home/myuser/Env/virtenv/local/lib/python2.7/site-packages/django/contrib/gis/geoip2/base.py" in __init__
95. self._city = geoip2.database.Reader(city_db, mode=cache)
File "/home/myuser/Env/virtenv/local/lib/python2.7/site-packages/geoip2/database.py" in __init__
82. self._db_reader = maxminddb.open_database(filename, mode)
File "/home/myuser/Env/virtenv/local/lib/python2.7/site-packages/maxminddb/__init__.py" in open_database
37. return maxminddb.reader.Reader(database, mode)
File "/home/myuser/Env/virtenv/local/lib/python2.7/site-packages/maxminddb/reader.py" in __init__
52. db_file.fileno(), 0, access=mmap.ACCESS_READ)
Exception Type: error at/
Exception Value: [Errno 12] Cannot allocate memory
지역 변수는 다음과 같습니다 :
Variable Value
database '/home/myuser/Env/virtenv/myproject/geoip/GeoLite2-City.mmdb'
db_file <closed file '/home/myuser/Env/virtenv/myproject/geoip/GeoLite2-City.mmdb', mode 'rb' at 0x7f8c5cf5d390>
mode 0
self <maxminddb.reader.Reader object at 0x7f8c5cf5f550>
내가 버추얼 박스를 사용하여 내 게스트 OS는 Ubuntu 16.04
입니다 여기에
uWSGI
에서 실행했을 때 얻는 예외입니다. 거기에 4GB 스왑 파일이 있습니다. 좀 RAM을 확보하면 문제가 계속. 나는 쉘에서 GeoIP2 개체를 만들 수 있습니다 내가 서버를 수동으로 실행도 것처럼 이 하지만, OS 수준의 메모리 문제가되지 않을 것이다. 내가 확인
다음 일이 내 프로젝트의 geoip
디렉토리가 www-data
소유하고 있다는 점이다 또한 www-data
가 소유 (GeoLite2-City.mmdb
및 GeoLite2-Country.mmdb
) 안에 775 두 파일을 가지고 있으며, 774
/etc/systemd/system/uwsgi.service
가 포함되어 있습니다
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown www-data:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
/etc/uwsgi/sites/my_site.ini
에는 다음이 포함
[uwsgi]
project = myproject
base = /home/myuser
home = %(base)/Env/virtenv/%(project)
binary-path = /usr/local/bin/uwsgi
chdir = %(home)
chmod-socket = 660
chown-socket = www-data:www-data
#emperor = true
#enable-threads = true
gid = www-data
limit-as = 1024
logto = /tmp/uwsgi.log
master = true
module = myproject.wsgi:application
pidfile = /opt/logs/uwsgi/master.pid
# number of cores on machine
processes = 2
python-path = %(home)
py-autoreload = 2
socket = /run/uwsgi/%(project).sock
uid = www-data
vacuum = true
virtualenv = %(base)/Env/virtenv
vhost = true
workers = 4
env = AWS_KEY=***************
env = AWS_SECRET=***************
env = DJANGO_SETTINGS_MODULE=myproject.settings.local
env = GMAIL_PASS=***************
env = PSQL_PASS=***************
env = SECRET_KEY=*********************************************
의 한계가 어디 691,363,210
이 궁금?
htop과 같은 방법으로 VM 메모리 사용을 모니터링 할 수 있습니까? – shalbafzadeh
htop에서 확인한 결과 RAM이 1.5GB 남았습니다. – katericata