一个的doGet()内部的servlet一个非常简单的Java代码变得比的CPU时间上GAE的第二多。我看过一些配额相关文件,显然我没有做错什么。

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

这上面的代码告诉我的唯一的是,检查头将使用超过CPU时间的第二(1000毫秒),其为谷歌是日志面板上显示警告。这似乎是一个非常简单的请求,仍然是使用多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");} }
有帮助吗?

解决方案

有不再在App Engine任何每分钟配额。任何引用这些信息是过时。如果你想要做的更好的CPU使用的分析,你可能想尝试一下新发布的将Appstats为Java

其他提示

您日志显示,只有缓慢有时。

是你的servlet对象的构造很慢?

  

这上面的代码告诉我的唯一的是,检查头将使用超过CPU时间的第二(1000毫秒),其为谷歌是日志面板上显示警告。这似乎是一个非常简单的请求,并仍然被使用多于CPU的第二个。

这是否也发生没有调用配额API?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top