如何在不超过分钟配额的情况下在Google应用程序引擎上使用Java?
doGet()servlet中的一个非常简单的java代码在GAE上占用了超过一秒钟的cpu时间。我已经阅读了一些与配额相关的文档,显然我没有做错任何事情如何在不超过分钟配额的情况下在Google应用程序引擎上使用Java?,java,google-app-engine,quota,Java,Google App Engine,Quota,doGet()servlet中的一个非常简单的java代码在GAE上占用了超过一秒钟的cpu时间。我已经阅读了一些与配额相关的文档,显然我没有做错任何事情 //Request the user Agent info String userAgent = req.getHeader("User-Agent"); 我想知道什么是使用CPU最多的,我使用谷歌帮助推荐 //The two lines below will get the CPU before requesting User-A
//Request the user Agent info
String userAgent = req.getHeader("User-Agent");
我想知道什么是使用CPU最多的,我使用谷歌帮助推荐
//The two lines below will get the CPU before requesting User-Agent Information
QuotaService qs = QuotaServiceFactory.getQuotaService();
long start = qs.getCpuTimeInMegaCycles();
//Request the user Agent info
String userAgent = req.getHeader("User-Agent");
//The three lines below will get the CPU after requesting User-Agent Information
// and informed it to the application log.
long end = qs.getCpuTimeInMegaCycles();
double cpuSeconds = qs.convertMegacyclesToCpuSeconds(end - start);
log.warning("CPU Seconds on geting User Agent: " + cpuSeconds);
上面的代码告诉我的唯一一件事是,检查报头将使用超过1秒(1000ms)的cpu时间,这对于Google来说是日志面板上的一个警告。这似乎是一个非常简单的请求,并且仍然使用超过一秒钟的cpu
我错过了什么
下面是供大家娱乐的日志图片。 为了大家的利益,我发布了完整的代码
@SuppressWarnings("serial")
public class R2CComingSoonSiteServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(R2CComingSoonSiteServlet.class.getName());
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
//The two lines below will get the CPU before requesting User-Agent Information
QuotaService qs = QuotaServiceFactory.getQuotaService();
long start = qs.getCpuTimeInMegaCycles();
//Request the user Agent info
String userAgent = req.getHeader("User-Agent");
//The three lines below will get the CPU after requesting User-Agent Information
// and informed it to the application log.
long end = qs.getCpuTimeInMegaCycles();
double cpuSeconds = qs.convertMegacyclesToCpuSeconds(end - start);
log.warning("CPU Seconds on geting User Agent: " + cpuSeconds);
userAgent = userAgent.toLowerCase();
if(userAgent.contains("iphone"))
resp.sendRedirect("/mobIndex.html");
else
resp.sendRedirect("/index.html");} }
上面的代码告诉我的唯一一件事是,检查报头将使用超过1秒(1000ms)的cpu时间,这对于Google来说是日志面板上的一个警告。这似乎是一个非常简单的请求,并且仍然使用超过一秒钟的cpu
如果没有对配额API的调用,这种情况也会发生吗?您的日志显示,它只是有时很慢
servlet对象的构造真的很慢吗?appengine上不再有任何每分钟的配额。任何引用它们的消息都已过期。如果您想更好地分析您的CPU使用情况,您可能需要试用新发布的。是的,对配额api的调用是为了找到根本原因而实现的。我调查这个问题的最初原因是日志警告图标,通知我我的应用程序在给定的servlet上使用了超过一秒钟的处理时间。是的,可能只是记录时间,在有和没有配额代码调用的情况下输入和输出。如果对
req.getHeader
的调用(取决于容器实现)是对预初始化映射的查找,那么我会非常惊讶。@Geo:对于一个什么都不做的Servlet如何?嗨,Stephen,谢谢你的帖子。我刚刚为您添加了完整的servlet代码。这是一个单一用途的servlet,没有什么特别之处。嘿,尼克,你能给我发一份官方的谷歌新闻稿,其中每分钟的配额被删除了吗?我不相信我们发布了任何形式的新闻稿-如果我们为每一个新功能发布一份,我们就不会做任何其他事情了!不过,它很可能出现在发行说明中。