【问题标题】:Warm up requests not working in Cloud Endpoints Objectify预热请求在 Cloud Endpoints Objectify 中不起作用
【发布时间】:2017-05-08 03:04:02
【问题描述】:

我一直在尝试使用 Objectify 在我的 Endpoints 项目中工作的热身请求,但似乎没有任何效果。有什么我错过的吗?我尝试了两种方法:

小服务程序:

 public class WarmUpServ extends HttpServlet {

        static {
            ObjectifyService.factory().register(CounterEnt.class);
            ObjectifyService.factory().register(CounterShard.class);
        }

        @Override
        public void init() throws ServletException {
            super.init();
        }

        @Override
        public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException {

        }

        @Override
        public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        }
    }

web.xml

<servlet>
    <servlet-name>warm-up</servlet-name>
    <servlet-class>com.myapp.backend.WarmUpServ</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>warm-up</servlet-name>
    <url-pattern>/war-up</url-pattern>
</servlet-mapping>

我还尝试了一个监听器:

public class WarmUpServListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ObjectifyService.factory().register(CounterEnt.class);
        ObjectifyService.factory().register(CounterShard.class);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    }
}

web.xml

<listener>
    <listener-class>com.myapp.backend.WarmUpServListener</listener-class>
</listener>

注意:我需要以这种方式注册我的实体,因为我有一个依赖项,它直接使用ObjectifyService

【问题讨论】:

    标签: google-app-engine google-cloud-endpoints objectify


    【解决方案1】:

    不保证会发出预热请求。

    https://cloud.google.com/appengine/docs/standard/java/warmup-requests/

    如果为您的应用启用预热请求,App Engine 尝试检测您的应用程序何时需要新实例并 发起一个预热请求来初始化一个新的实例。然而, 这些检测尝试并非在所有情况下都有效。结果,你 可能会遇到加载请求,即使启用了预热请求 在您的应用程序中。例如,如果您的应用不提供流量,则第一个 对应用程序的请求将始终是加载请求,而不是预热 请求。

    改用ServletContextListener;每次实例启动时都会调用一次。

    【讨论】:

    • 好的。为什么我上面的 ServletContextListener 不起作用?我的代码中是否缺少某些内容?
    • 您的听众在我看来很好。 “不起作用”是什么意思?什么是不良行为?您是否尝试过设置调试器断点以确保您的代码被调用?
    猜你喜欢
    • 2014-09-12
    • 2012-06-08
    • 2018-12-15
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2020-05-05
    相关资源
    最近更新 更多