应用程序引擎动态后端在开发模式下无法按预期运行
此问题已在开发模式(Eclipse...)中进行了测试并发生。
我有一个配置的后端(在 backends.xml 中):
<backends>
<backend name="example">
<class>B8</class>
<options>
<instances>1</instances>
<public>false</public>
<dynamic>true</dynamic>
</options>
</backend>
</backends>
如您所见,它被明确设置为“动态”。
这是我的 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>
.. 只是后端的常规 servlet 入口点。
这是后端的 Java 代码:
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!");
}
}
现在,当我按 F11 并开始调试应用程序时,这是控制台中的输出:
INFO: The server is running at http://localhost:8888/
Backend started!
Backend terminating!
如果我理解 此文档行正确,它不应该启动,直到我请求 /_ah/start
(http)。 它清楚地说:
当您启动动态后端时,App Engine 允许它接受 流量,但 /_ah/start 请求不会发送到实例,直到 它收到第一个用户请求。
与此问题相关的另一个副作用是后端似乎永远不会“停止”,我的意思是它仍然处于“运行”状态(正如我在 http://127.0.0.1:8888/_ah/admin/backends )。
终止后(在上面的代码中,因为它在控制台中清楚地打印出来),不应该在几分钟后关闭吗? (我等了大约20分钟)。
我做错了什么?
顺便说一句,我的最终目标是在“后端”上下文中运行一些代码,就像运行“任务”一样。我想要一个“后端”,因为 CPU/RAM 能力强并且没有时间限制。
请赐教。 谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SDK 并不总是准确反映生产环境。启动和关闭后端可能是这种情况之一。
如果您发现后端在生产中的行为符合预期,请提交错误 SDK。
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.