预热请求在 Cloud Endpoints Objectify 中不起作用
Warm up requests not working in Cloud Endpoints Objectify
我一直在尝试使用 Objectify 来预热请求以在我的 Endpoints 项目中工作,但似乎没有任何效果。我错过了什么吗?我尝试了两种方法:
servlet:
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
的依赖项。
预热请求不保证一定会被执行。
https://cloud.google.com/appengine/docs/standard/java/warmup-requests/
If warmup requests are enabled for your application, App Engine
attempts to detect when your application needs a new instance and
initiates a warmup request to initialize a new instance. However,
these detection attempts do not work in every case. As a result, you
might encounter loading requests, even if warmup requests are enabled
in your app. For example, if your app is serving no traffic, the first
request to the app will always be a loading request, not a warmup
request.
改用ServletContextListener
;每次实例启动时都会调用一次。
我一直在尝试使用 Objectify 来预热请求以在我的 Endpoints 项目中工作,但似乎没有任何效果。我错过了什么吗?我尝试了两种方法:
servlet:
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
的依赖项。
预热请求不保证一定会被执行。
https://cloud.google.com/appengine/docs/standard/java/warmup-requests/
If warmup requests are enabled for your application, App Engine attempts to detect when your application needs a new instance and initiates a warmup request to initialize a new instance. However, these detection attempts do not work in every case. As a result, you might encounter loading requests, even if warmup requests are enabled in your app. For example, if your app is serving no traffic, the first request to the app will always be a loading request, not a warmup request.
改用ServletContextListener
;每次实例启动时都会调用一次。