开发者

Avg Cpu , URI uses a hight amount of cpu

Hello i use a servlet that contains a persistence manager object with two objects and when i use it in the dashboard i have this message:

"This URI uses a hight amount of cpu and may soon exceed its quota."

I have 2300 for the avg Cpu for this uri, why it takes so long?

When i'm looking the log at the beginning i have a hight amount of cpu for example 2000 and after i have less than 200 why ?

And 10 min later when i come back i have a hight amount of cpu again why?

It could be possible to reduce this time ?

Edit : code

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

    String param1 = req.getParameter("param1");
    Strin开发者_如何学Gog 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");
    }
}


Thats because of cold starts of google app engine.

Because the way google app engine works, it kills your application instance if no request is seen for some time. So first request after some rest takes longer time and further requests are relatively quick.

There are many threads that discuss this problem and possible solutions which mostly describe two solutions -

  1. Optimize your code for startups
  2. [Not recommended] Creating cron or any other kind of periodic HTTP requests to keep instance up and running. This is a really bad approach and I dont recommend this because it adversely affects the whole purpose and idea of how clouds work.

Here are some references that discuss more about this problem:

  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…
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜