避免 Heroku 服务器休眠 [英] Avoid heroku server from sleeping

查看:48
本文介绍了避免 Heroku 服务器休眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Heroku 服务器上托管了一个网站(顺便说一下,我是 Heroku 的新手),并且由于它在免费包下,它会在 30 米不活动 后休眠,并在用户点击它时再次启动它,大约需要 7 秒才能 npm run start 成功.

I got a website hosted on a Heroku server (i'm a new to Heroku btw), and as it's under the free package, it sleeps after 30m of inactivity, and to put it in action again when a user hits it, it takes around 7 secs to npm run start successfully.

我正在考虑运行一个 nodejs 作业或每 29 米打开一次网站的东西,这样服务器就不会休眠,最初,我得到了这样的东西:

I'm thinking of run a nodejs job or something that open the website every 29m so that the server never sleeps, initially, I got something like this:

(function wakeup() {
  require('open')('https://mywebsite.herokuapp.com', (err) => {
    if (err) throw err;
    console.log('Woke up!');
    setTimeout(wakeup, 1740000); //29m
  });
})()

注意:这只是在浏览器中打开它,但不处理关闭它.

  • 首先,这种变通办法是否合法?
  • 第二,如果是的话,实现这一点的最佳方法是什么?

推荐答案

让您的免费 dyno 保持清醒是完全合法的,只要您愿意,您可以随意使用任何方式.请注意,您每月分配的免费测功时间是有限的.如果您使用信用卡验证了您的 Heroku 帐户,则您每月有 1000 个免费的 dyno 小时,这足以让一个免费的网络 dyno永远"运行而根本不睡觉.一个非常简单的方法就是为您的应用程序配置一个 New Relic 附加组件(使用免费的 New Relic 计划),您可以轻松配置该计划以定期 ping 您的 Heroku 应用程序.有关防止 Heroku 应用程序空闲的其他方法,请参阅 这里.

It is perfectly legal to keep your free dyno awake for as long as you want, by any means at your disposal. Just note that your monthly allocation of free dyno hours is limited. If you verified your Heroku account with a credit card, you have 1000 free dyno hours per month, which is more than enough to keep a single free web dyno up "forever" without sleeping at all. A very easy way to do that is simply to configure a New Relic add-on for your app (using the free New Relic plan), which you can easily configure to ping your Heroku app periodically. For additional methods to prevent your Heroku app from idling, see here.

这篇关于避免 Heroku 服务器休眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆