繁体   English   中英

如何在不超过微小配额的情况下在Google App Engine上使用Java?

[英]How to use Java on Google App Engine without exceeding minute quotas?

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-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);

上面代码告诉我的唯一事情是检查标头将使用超过一秒(1000毫秒)的CPU时间,这对于Google来说是日志面板上的警告。 这似乎是一个非常简单的请求,仍然使用超过一秒的CPU。

我错过了什么?


每个人的娱乐日志图像下方。 Google App Engine慢速报告的日志

为了所有人的利益,我发布了完整的代码。

@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");} }

App Engine上不再有每分钟的配额。 任何引用它们的消息都已过时。 如果您想更好地分析CPU使用情况,可能需要尝试新发布的Java应用程序

上面代码告诉我的唯一事情是检查标头将使用超过一秒(1000毫秒)的CPU时间,这对于Google来说是日志面板上的警告。 这似乎是一个非常简单的请求,仍然使用超过一秒的CPU。

如果没有调用配额API,是否也会发生这种情况?

您的日志显示它有时很慢。

你的servlet对象的构造真的很慢吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM