代码之家  ›  专栏  ›  技术社区  ›  Geo

如何在不超过分钟配额的情况下在googleappengine上使用Java?

  •  7
  • Geo  · 技术社区  · 16 年前

    //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。

    我错过了什么?


    下面的日志图片供大家娱乐。 logs for Google App Engine Slow Reports

    我张贴完整的代码,为大家的利益。

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

    3 回复  |  直到 6 年前
        1
  •  4
  •   Nick Johnson    16 年前

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

        2
  •  0
  •   Stephen Denne    16 年前

    你的日志显示它只是有时很慢。

        3
  •  0
  •   Thilo    16 年前

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