I've been trying to get warm up requests to work in my Endpoints project using Objectify but nothing seems to be working. Is there something I missed? I tried two methods:
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>
And I also tried a listener:
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>
Note: I need to register my entities this way because I have a dependency where it uses ObjectifyService
directly.
Warmup requests are not guaranteed to be made.
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.
Use a ServletContextListener
instead; that will always be called once at each instance start.