服务器错误 - heroku,django

时间:2013-04-12 11:57:10

标签: django heroku

部署代码并访问网站后,我遇到了H20错误。这是日志:

2013-04-12T11:45:59.304354+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path=/ host=olp-website.herokuapp.com fwd="86.151.6.106" dyno= connect= service= status=503 bytes=

所以我试着看看dynos:

heroku ps --app olp-website

    === web: newrelic-admin run-program gunicorn -c gunicorn.py.ini wsgi:application
    web.1: up 2013/04/12 12:46:21 (~ 1m ago)

heroku ps:restart --app olp-website

    Restarting processes... done

heroku ps --app olp-website

    === web: newrelic-admin run-program gunicorn -c gunicorn.py.ini wsgi:application
    web.1: starting 2013/04/12 12:48:42 (~ 6s ago)

现在收到500内部服务器错误:

2013-04-12T13:38:19.116492+00:00 app[web.1]: 2013-04-12 13:38:19 [2] [INFO] Listening at: http://0.0.0.0:28853 (2)
2013-04-12T13:38:19.115928+00:00 app[web.1]: 2013-04-12 13:38:19 [2] [INFO] Starting gunicorn 0.14.3
2013-04-12T13:38:19.116593+00:00 app[web.1]: 2013-04-12 13:38:19 [2] [INFO] Using worker: gevent
2013-04-12T13:38:19.122714+00:00 app[web.1]: 2013-04-12 13:38:19 [5] [INFO] Booting worker with pid: 5
2013-04-12T13:38:19.135537+00:00 app[web.1]: 2013-04-12 13:38:19 [7] [INFO] Booting worker with pid: 7
2013-04-12T13:38:19.129099+00:00 app[web.1]: 2013-04-12 13:38:19 [6] [INFO] Booting worker with pid: 6
2013-04-12T13:38:19.140715+00:00 app[web.1]: 2013-04-12 13:38:19 [8] [INFO] Booting worker with pid: 8
2013-04-12T13:38:19.393488+00:00 heroku[web.1]: State changed from starting to up
2013-04-12T13:38:20.310391+00:00 app[web.1]: 2013-04-12 13:38:20,310 (5/Dummy-2) newrelic.core.agent INFO - New Relic Python Agent (1.3.0.289)
2013-04-12T13:38:21.072892+00:00 heroku[router]: at=info method=GET path=/ host=olp-website.herokuapp.com fwd="86.151.6.106" dyno=web.1 connect=31ms service=761ms status=500 bytes=5

我看不出有什么问题,因为代码在开发中运行良好,我正在使用django-skel设置文件进行生产。

您是否知道可能设置错误的内容?

编辑:只是查看heroku上的数据库信息,看起来数据库有0个表 - 所以我猜sqlite数据库没有迁移到postresql。

1 个答案:

答案 0 :(得分:0)

H20错误通常意味着您的应用程序在闲置后需要很长时间才能启动。

The router will enqueue requests for 75 seconds while waiting for starting processes to reach an “up” state. If after 75 seconds, no web dynos have reached an “up” state, the router logs H20 and serves a standard error page.

您必须检查该资产是否已预编译,或者是否存在其他可能会降低应用启动速度的因素。

调试超时:

请求超时的一个原因是代码中的无限循环。在本地测试,看看你是否可以复制问题并修复bug。

另一种可能性是您尝试在Web流程中执行某种长期运行的任务,例如:

Sending an email
Accessing a remote API 
Web scraping / crawling
Rendering an image or PDF
Heavy computation 
Heavy database usage (slow or numerous queries)

如果是这样,您应该将这个繁重的工作移到后台作业中,后台作业可以从您的Web请求中异步运行。

当应用程序使用的外部服务不可用或超载时,会发生另一类超时。在这种情况下,除非将工作移至后台,否则您的Web应用程序很可能会超时。在某些情况下,您必须在Web请求期间处理这些请求,您应该始终计划失败案例。