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

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

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

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


当前回答

伙计,这是一个你可以运行的英雄应用程序,让多个英雄应用程序存活下来。只需在config.json中添加你想要ping的url。

https://github.com/jcarras/rise-and-shine

其他回答

还有一个有效的解决方案:wokeDyno 以下是一篇博客文章是如何工作的: 它很容易集成到应用程序中:

/* Example: as used with an Express app */

const express = require("express")
const wakeDyno = require("woke-dyno");

// create an Express app
const app = express();

// start the server, then call wokeDyno(url).start()
app.listen(PORT, () => {
    wakeDyno(DYNO_URL).start(); // DYNO_URL should be the url of your Heroku app
});

在一个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();
}
}

Freshping是另一种免费资源,可以让你的免费Heroku应用全天候有效。

我已经写下了步骤:

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

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

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

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