在Heroku的免费应用程序中,dyno似乎一直在空转——我的应用程序流量很低,但在我的情况下,我的用户不得不等待20多秒才能启动一个新的dyno,这也是不能接受的。

坦率地说,在这样的等待下,许多人甚至在第一页显示之前就离开了。

所以,我遇到了一个问题:当我每天的流量都在个位数时,我是否应该每月支付36美元来为每个用户节省令人尴尬的漫长20秒?

有没有办法解决这个问题?


当前回答

将应用程序的URL添加到http://kaffeine.herokuapp.com/。

来自网站:

Kaffeine每30分钟ping一次你的Heroku应用,所以它永远不会睡觉*

其他回答

我已经写下了步骤:

➜将gem 'newrelic_rpm'添加到您的Gemfile下的staging & production ➜bundle install ➜登录到heroku控制面板并添加newrelic插件 ➜一旦添加,设置自动ping到你的网站,这样它就不会闲置 ➜浏览菜单>可用性监控(在设置下) →点击“开启可用性监控” ➜输入要ping的url(例如:http://spokenvote.org) ➜选择1分钟为间隔

答案很简单——如果你看重服务,那就付钱。

所有这些获得付费服务的“技巧”……这就像偷有线电视一样。甚至在这里列出它们都是值得怀疑的。接下来是什么,盗版游戏的技巧吗?

就像这里的另一个帖子一样,我很重视开发和测试的免费服务,如果Heroku因为有太多的白吃白喝的人而取消它,我会对你们这些道德受损的人感到非常恼火。我只是觉得他的批评不够直接。

在一个spring应用程序中,每2分钟向根url路径发出一个HTTP请求 `

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestTemplate;

public class HerokuNotIdle {

private static final Logger LOG = LoggerFactory.getLogger(HerokuNotIdle.class);

@Scheduled(fixedDelay=120000)
public void herokuNotIdle(){
    LOG.debug("Heroku not idle execution");
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getForObject("http://yourapp.herokuapp.com/", Object.class);
}
}

记住,配置上下文以启用调度器并为调度器创建bean

@EnableScheduling
public class AppConfig {

@Bean
public HerokuNotIdle herokuNotIdle(){
    return new HerokuNotIdle();
}
}

这里的大多数答案都已经过时或目前不起作用。目前个人账户的免费层是每月提供550个免费dyno小时。

一个经过验证的免费账户可以给你1000小时的免费动态。我写了一篇关于如何让我的免费应用保持清醒的文章。

https://link.medium.com/uDHrk5HAD0

希望它能帮助到2019年需要解决方案的人

我有一个只需要在周一到周五午餐时间运行的应用程序。 我刚刚在crontab中添加了以下脚本:

#!/bin/sh
# script to unidle heroku installation for the use with cronjob
# usage in crontab:
# */5 11-15 * * 1-5 /usr/local/bin/uptimer.sh http://www.example.com
# The command /usr/local/bin/uptimer.sh http://www.example.com will execute every 5th minute of 11am through 3pm Mondays through Fridays in every month.
# resources: http://www.cronchecker.net
echo url to unidle: $1
echo [UPTIMER]: waking up at:
date
curl $1
echo [UPTIMER]: awake at:
date

因此,对于任何应用程序,只需在crontab中删除另一行:

*/5 11-15 * * 1-5 /usr/local/bin/uptimer.sh http://www.example.com