This issue was tested, and occurs, in the dev mode (Eclipse...).
I have one configured backend (in backends.xml):
<backends>
<backend name="example">
<class>B8</class>
<options>
开发者_如何学运维 <instances>1</instances>
<public>false</public>
<dynamic>true</dynamic>
</options>
</backend>
</backends>
As you see it's explicitly set to be 'dynamic'.
This is my web.xml:
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>backend_test</servlet-name>
<servlet-class>BackendTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>backend_test</servlet-name>
<url-pattern>/_ah/start</url-pattern>
</servlet-mapping>
</web-app>
.. just a regular servlet entry-point to the backend.
And here's the backend's Java code:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class BackendTest extends HttpServlet
{
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
System.out.println("Backend started!");
// ............
System.out.println("Backend terminating!");
}
}
Now, when I hit F11 and start debugging the app, this is the output in the console:
INFO: The server is running at http://localhost:8888/
Backend started!
Backend terminating!
If I understand this doc line correctly it shouldn't start, until I request /_ah/start
(http).
It clearly says:
When you start a dynamic backend, App Engine allows it to accept traffic, but the /_ah/start request is not sent to an instance until it receives its first user request.
Another side-effect, related to this issue, is that the backend seem to never be "stopped", I mean it remains in the "running" state (as I see in the admin area at http://127.0.0.1:8888/_ah/admin/backends ).
After it was terminated (in the code above, as it clearly printed out in the console), shouldn't it be shutdown after a few minutes? (I'm waiting about 20min).What am I doing wrong?
By the way, my final goal is to run some code within a "Backend" context, just like running a "Task". I want a "Backend" because of the CPU/RAM power and the no-time-limit.
Please enlighten me. Thanks!
The SDK doesn't always exactly reflect the production environment. Starting up and shutting down backends is likely to be one area in which that is the case.
If you find the backend behaves as expected in production, please file a bug for the SDK.
精彩评论