Avg Cpu,URI使用大量的cpu

时间:2010-08-19 13:50:35

标签: google-app-engine

您好我使用的servlet包含一个具有两个对象的持久性管理器对象,当我在仪表板中使用它时,我有这样的消息:

“此URI使用了大量的cpu,可能很快就会超出其配额。”

这个uri的avg Cpu有2300,为什么需要这么长时间?

当我在开头查看日志时,我有一个高容量的CPU,例如2000,之后我有少于200的原因?

10分钟后,当我回来的时候,为什么还有高容量的cpu?

有可能缩短这个时间吗?

编辑:代码

public void doGet(HttpServletRequest req,HttpServletResponse resp)抛出IOException {

    String param1 = req.getParameter("param1");
    String param2 = req.getParameter("param2");

    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Myclass.class.getName()+
    "where parameter1 == param1 && parameter2 == param2 "+
    "parameters String param1, String param2";

List<Myclass> result = (List<Myclass>) pm.newQuery(query).execute(param1, param2);

    if(result.isEmpty()) {
        pm.close();
        resp.sendRedirect("/welcome.jsp");
    }
    else {
        pm.close();
        resp.sendRedirect("/question.jsp");
    }
}

1 个答案:

答案 0 :(得分:3)

这是因为谷歌应用引擎的cold starts

由于谷歌应用引擎的工作方式,如果一段时间内没有看到任何请求,它会杀死您的应用程序实例。因此,在休息一段时间之后首先请求需要更长的时间,并且进一步的请

有很多线程讨论这个问题和可能的解决方案,主要描述两个解决方案 -

  1. 优化初创公司的代码
  2. [不推荐]创建cron或任何其他类型的定期HTTP请求以保持实例正常运行。这是一个非常糟糕的方法,我不推荐这个,因为它会对整个目的和云的工作方式产生负面影响。
  3. 以下是一些讨论此问题的更多参考资料:

    1. App instance recycling and response times - is there solution?
    2. Application instances seem to be too aggressively recycled
    3. Uneven response time between connection to server to first byte sent
    4. Google App Engine application instance recycling and response times…