为什么 Heroku 托管的应用程序需要很长时间才能启动?
我最近创建了我的第一个 Heroku 应用程序,发现了一些奇怪的行为:
当应用程序有一段时间没有被访问时,我认为服务器会关闭。然后,如果您访问它,大约需要 20 秒才能启动它才会响应。在这个初始启动阶段之后,它会快速响应。
有没有办法避免这个“启动/关闭”阶段?
I recently created my first Heroku application and I'm finding some strange behavior:
When the application hasn't been accessed in a while, I think the server shuts down. Then, if you access it, it takes about 20 seconds to start up before it responds. After this initial start up phase, it responds quickly.
Is there a way to avoid this "start up / shut down" phase?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,支付全职测功机的费用。 Heroku 文档指出,当您使用免费套餐时,如果您的 dyno 一段时间没有使用(根据我的经验为 30 分钟),它就会关闭。它会在下次收到请求时重新启动。
请参阅:http://devcenter.heroku.com/articles/dynos#frequently-asked -questions
Heroku 将其称为“Dyno Idling”。
Yes, pay for a full-time dyno. The Heroku docs state that when you're on the free tier if your dyno is not in use for a while (30 minutes in my experience) it shuts down. It restarts the next time it receives a request.
See: http://devcenter.heroku.com/articles/dynos#frequently-asked-questions
Heroku refers to his as "Dyno Idling."
除了安德鲁的答案,和/或如果您买不起额外的测功机,您可以实施 New Relic RPM 附加组件并使用其“可用性监控”功能。
它基本上每分钟会对您的应用程序执行两次 ping 操作,从而防止测功机空转。另外,您还可以获得性能测量功能。
Alternatively to Andrew's answer, and/or if you cannot afford an additional dyno, you can implement the New Relic RPM add-on and use their "availability monitoring" feature.
It will basically ping your application twice per minute, thus preventing the dyno from idling. Plus you get the performance measurement features.
这是因为 dynos 声明。您只需 ping 您的应用程序即可使其保持启动状态。查看这篇文章:
http://codeglot.com/posts/25-simple_way_to_keep_smaller_apps_loaded_on_herkou
It's because of dynos stating. You can just ping your app to keep it started. Checkout this post:
http://codeglot.com/posts/25-simple_way_to_keep_smaller_apps_loaded_on_herkou