【问题标题】:Avg Cpu , URI uses a hight amount of cpuAvg Cpu , URI 使用大量 cpu
【发布时间】:2011-04-01 03:33:21
【问题描述】:

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

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

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

当我在开始时查看日志时,我有大量的 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");
    }
}

【问题讨论】:

  • 如果没有看到代码,绝对不可能知道为什么您的代码会占用如此多的 CPU 时间。
  • 好的,我用代码编辑我的消息

标签: google-app-engine


【解决方案1】:

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

由于谷歌应用引擎的工作方式,如果一段时间内没有看到请求,它会终止您的应用程序实例。因此,休息一段时间后的第一次请求需要更长的时间,而进一步的请求相对较快。

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

  1. 为初创公司优化代码
  2. [不推荐] 创建 cron 或任何其他类型的定期 HTTP 请求以保持实例正常运行。这是一种非常糟糕的方法,我不建议这样做,因为它会对云工作的整个目的和想法产生不利影响。

以下是一些关于此问题的更多讨论的参考资料:

  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…

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多