如何在OpenShift上运行需要太多RAM的代码?

时间:2016-01-16 13:23:52

标签: python django openshift

我遇到OpenShift问题。目前我正在尝试将django_geoip添加到我的django应用中。但是,当我尝试初始化其数据库时,OpenShift会将其杀死。我认为这需要太多的记忆 如果我运行更新代码./manage.py geoip_update(我也尝试使用nohup运行),这是输出:

Downloading zipfile from ipgeobase.ru...
INFO:import:Downloading zipfile from ipgeobase.ru...
Extracting files...
INFO:import:Extracting files...
Updating locations...
INFO:import:Updating locations...
Updating CIDR...
INFO:import:Updating CIDR...
61%

61%的CIDR更新后,它崩溃了。如果我正在关注日志或通过ssh登录,它会让我失望:

/var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/ruby_compat.rb:30:in `select': closed stream (IOError)
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/ruby_compat.rb:30:in `io_select'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/transport/packet_stream.rb:75:in `available_for_read?'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/transport/packet_stream.rb:87:in `next_packet'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:183:in `block in poll_message'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178:in `loop'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178:in `poll_message'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:461:in `dispatch_incoming_packets'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:222:in `preprocess'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:206:in `process'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:170:in `block in loop'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:170:in `loop'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:170:in `loop'
from /var/lib/gems/1.9.1/gems/rhc-1.36.4/lib/rhc/ssh_helpers.rb:198:in `block in ssh_ruby'
from /var/lib/gems/1.9.1/gems/net-ssh-2.9.2/lib/net/ssh.rb:215:in `start'
from /var/lib/gems/1.9.1/gems/rhc-1.36.4/lib/rhc/ssh_helpers.rb:173:in `ssh_ruby'
from /var/lib/gems/1.9.1/gems/rhc-1.36.4/lib/rhc/commands/tail.rb:40:in `tail'
from /var/lib/gems/1.9.1/gems/rhc-1.36.4/lib/rhc/commands/tail.rb:21:in `run'
from /var/lib/gems/1.9.1/gems/rhc-1.36.4/lib/rhc/commands.rb:294:in `execute'
from /var/lib/gems/1.9.1/gems/rhc-1.36.4/lib/rhc/commands.rb:285:in `block (3 levels) in to_commander'
from /var/lib/gems/1.9.1/gems/commander-4.2.1/lib/commander/command.rb:180:in `call'
from /var/lib/gems/1.9.1/gems/commander-4.2.1/lib/commander/command.rb:180:in `call'
from /var/lib/gems/1.9.1/gems/commander-4.2.1/lib/commander/command.rb:155:in `run'
from /var/lib/gems/1.9.1/gems/commander-4.2.1/lib/commander/runner.rb:421:in `run_active_command'
from /var/lib/gems/1.9.1/gems/rhc-1.36.4/lib/rhc/command_runner.rb:72:in `run!'
from /var/lib/gems/1.9.1/gems/commander-4.2.1/lib/commander/delegates.rb:12:in `run!'
from /var/lib/gems/1.9.1/gems/rhc-1.36.4/lib/rhc/cli.rb:37:in `start'
from /var/lib/gems/1.9.1/gems/rhc-1.36.4/bin/rhc:20:in `<top (required)>'
from /usr/local/bin/rhc:23:in `load'
from /usr/local/bin/rhc:23:in `<main>'

我只是猜测内存使用量很大。我试图清空我的数据库并删除日志文件,以便我确定它不是容量问题(超出磁盘配额) 我的问题是:如何运行此命令才能使其正常工作?我可以以某种方式限制所需的资源吗?

1 个答案:

答案 0 :(得分:0)

我发现它是由geoip创建django_geoip_iprange表引起的,该表有大约218,000条记录。 Geoip可能会将所有这些ips加载到内存中,然后将它们存储到数据库中。我能够从localhost导入表django_geoip_iprange,所以django_geoip现在应该可以正常运行了。
此外,我应该能够使用ulimit来限制所需的资源。还没测试过。