So, I need to run my node.js app on heroku, it works very well, but when my app crashes, i need something to restart it, so i added forever to package.json, and created a file named forever.js with this:
所以,我需要在heroku上运行我的node.js应用程序,它运行得很好,但是当我的应用程序崩溃时,我需要重新启动它,所以我永远添加到package.json,并创建了一个名为forever.js的文件这个:
var forever = require('forever');
var child = new (forever.Monitor)('web.js', {
max: 3,
silent: false,
options: []
});
//child.on('exit', this.callback);
child.start();
forever.startServer(child);
on my Procfile (that heroku uses to know what to start) i put:
在我的Procfile(heroku用来知道起点)我把:
web: node forever.js
alright! Now everytime my app crashes it auto restarts, but, from time to time (almost every 1 hour), heroku starts throwing H99 - Platform error, and about this error, they say:
好的!现在每次我的应用程序崩溃它都会自动重启,但是,不时(几乎每1小时),heroku开始抛出H99 - 平台错误,并且关于这个错误,他们说:
Unlike all of the other errors which will require action from you to correct, this one does not require action from you. Try again in a minute, or check the status site.
与需要您纠正的所有其他错误不同,此错误不需要您采取任何操作。请在一分钟后重试,或查看状态网站。
But I just manually restart my app and the error goes away, if I don't do that, it may take hours to go away by itself.
但我只是手动重启我的应用程序,错误就消失了,如果我不这样做,它可能需要几个小时才能自行消失。
Can anyone help me here? Maybe this is a forever problem? A heroku issue?
有人能帮我一下吗?也许这是一个永远的问题?一个heroku问题?
1 个解决方案
#1
9
This is an issue with free Heroku accounts: Heroku automatically kills unpaid apps after 1 hour of inactivity, and then spins them back up the next time a request comes in. (As mentioned below, this does not apply to paid accounts. If you scale up to two servers and pay for the second one, you get two always-on servers.) - https://devcenter.heroku.com/articles/dynos#dyno-sleeping
这是免费Heroku帐户的问题:Heroku会在1小时不活动后自动杀死未付费的应用,然后在下次请求时将其旋转回来。(如下所述,这不适用于付费帐户。如果您扩展最多两个服务器并为第二个服务器付费,您将获得两个永远在线的服务器。) - https://devcenter.heroku.com/articles/dynos#dyno-sleeping
This behavior is probably not playing nicely with forever
. To confirm this, run heroku logs
and look for the lines "Idling" and " Stopping process with SIGTERM" and then see what comes next.
这种行为可能永远不会很好地发挥作用。要确认这一点,请运行heroku日志并查找“空闲”和“使用SIGTERM停止进程”行,然后查看接下来的内容。
Instead of using forever
, you might want to try the using the Cluster API and automatically create a new child each time one dies. http://nodejs.org/api/cluster.html#cluster_cluster is a good example, you'd just put your code into the else
block.
您可能希望尝试使用Cluster API并在每次死亡时自动创建一个新子项,而不是永远使用。 http://nodejs.org/api/cluster.html#cluster_cluster就是一个很好的例子,你只需将代码放入else块即可。
The upshot is that your app is now much more stable, plus it gets to use all of the available CPU cores (4 in my experience).
结果是您的应用程序现在更稳定,而且它可以使用所有可用的CPU核心(根据我的经验,4)。
The downside is that you cannot store any state in memory. If you need to store sessions or something along those lines, try out the free Redis To Go addon (heroku addons:add redistogo
).
缺点是你不能将任何状态存储在内存中。如果您需要存储会话或其他内容,请尝试免费的Redis To Go插件(heroku插件:添加redistogo)。
Here's an example that's currently running on heroku using cluster
and Redis To Go: https://github.com/nfriedly/node-unblocker
这是一个使用集群和Redis To Go在heroku上运行的示例:https://github.com/nfriedly/node-unblocker
UPDATE: Heroku has recently made some major changes to how free apps work, and the big one is they can only be online for a maximum of 18 hours per day, making it effectively unusable as a "real" web server. Details at https://blog.heroku.com/archives/2015/5/7/heroku-free-dynos
更新:Heroku最近对免费应用程序的工作方式做了一些重大改动,最重要的是他们每天最多只能在线工作18小时,这使得它无法像“真正的”网络服务器一样无法使用。详情请访问https://blog.heroku.com/archives/2015/5/7/heroku-free-dynos
UPDATE 2: They changed it again. Now, if you verify your ID, you can run 1 free dyno constantly: https://blog.heroku.com/announcing_heroku_free_ssl_beta_and_flexible_dyno_hours#flexible-free-dyno-hours
更新2:他们再次改变了它。现在,如果您验证您的ID,您可以经常运行1个免费的dyno:https://blog.heroku.com/announcing_heroku_free_ssl_beta_and_flexible_dyno_hours#flexible-free-dyno-hours
#1
9
This is an issue with free Heroku accounts: Heroku automatically kills unpaid apps after 1 hour of inactivity, and then spins them back up the next time a request comes in. (As mentioned below, this does not apply to paid accounts. If you scale up to two servers and pay for the second one, you get two always-on servers.) - https://devcenter.heroku.com/articles/dynos#dyno-sleeping
这是免费Heroku帐户的问题:Heroku会在1小时不活动后自动杀死未付费的应用,然后在下次请求时将其旋转回来。(如下所述,这不适用于付费帐户。如果您扩展最多两个服务器并为第二个服务器付费,您将获得两个永远在线的服务器。) - https://devcenter.heroku.com/articles/dynos#dyno-sleeping
This behavior is probably not playing nicely with forever
. To confirm this, run heroku logs
and look for the lines "Idling" and " Stopping process with SIGTERM" and then see what comes next.
这种行为可能永远不会很好地发挥作用。要确认这一点,请运行heroku日志并查找“空闲”和“使用SIGTERM停止进程”行,然后查看接下来的内容。
Instead of using forever
, you might want to try the using the Cluster API and automatically create a new child each time one dies. http://nodejs.org/api/cluster.html#cluster_cluster is a good example, you'd just put your code into the else
block.
您可能希望尝试使用Cluster API并在每次死亡时自动创建一个新子项,而不是永远使用。 http://nodejs.org/api/cluster.html#cluster_cluster就是一个很好的例子,你只需将代码放入else块即可。
The upshot is that your app is now much more stable, plus it gets to use all of the available CPU cores (4 in my experience).
结果是您的应用程序现在更稳定,而且它可以使用所有可用的CPU核心(根据我的经验,4)。
The downside is that you cannot store any state in memory. If you need to store sessions or something along those lines, try out the free Redis To Go addon (heroku addons:add redistogo
).
缺点是你不能将任何状态存储在内存中。如果您需要存储会话或其他内容,请尝试免费的Redis To Go插件(heroku插件:添加redistogo)。
Here's an example that's currently running on heroku using cluster
and Redis To Go: https://github.com/nfriedly/node-unblocker
这是一个使用集群和Redis To Go在heroku上运行的示例:https://github.com/nfriedly/node-unblocker
UPDATE: Heroku has recently made some major changes to how free apps work, and the big one is they can only be online for a maximum of 18 hours per day, making it effectively unusable as a "real" web server. Details at https://blog.heroku.com/archives/2015/5/7/heroku-free-dynos
更新:Heroku最近对免费应用程序的工作方式做了一些重大改动,最重要的是他们每天最多只能在线工作18小时,这使得它无法像“真正的”网络服务器一样无法使用。详情请访问https://blog.heroku.com/archives/2015/5/7/heroku-free-dynos
UPDATE 2: They changed it again. Now, if you verify your ID, you can run 1 free dyno constantly: https://blog.heroku.com/announcing_heroku_free_ssl_beta_and_flexible_dyno_hours#flexible-free-dyno-hours
更新2:他们再次改变了它。现在,如果您验证您的ID,您可以经常运行1个免费的dyno:https://blog.heroku.com/announcing_heroku_free_ssl_beta_and_flexible_dyno_hours#flexible-free-dyno-hours