java - 如何在不超过分钟配额的情况下在 Google App Engine 上使用 Java?

标签 java google-app-engine quota

doGet() servlet 中的一个非常简单的 java 代码在 GAE 上占用了超过一秒的 cpu 时间。我已经阅读了一些与配额相关的文档,显然我没有做错任何事。

//Request the user Agent info
String userAgent = req.getHeader("User-Agent");

我想知道什么使用 CPU 最多,我使用了 google 帮助推荐。

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

上面的代码告诉我的唯一一件事是检查 header 将使用超过一秒(1000 毫秒)的 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");} }

最佳答案

App Engine 上不再有任何每分钟配额。任何提及它们的消息都已过时。如果你想更好地分析你的 CPU 使用率,你可能想试试新发布的 appstats for Java .

关于java - 如何在不超过分钟配额的情况下在 Google App Engine 上使用 Java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2535607/

相关文章:

mysql - 有没有一种方法或技术可以实现基于用户的数据库资源分配?

root 用户的 Linux 组配额?

Java泛型方法问题

node.js - Google App Engine 和 Travis CI 上的 NodeJS 环境变量

python - appengine、urlfetch 和内容长度 header

python - 匹配数据存储查询中的所有记录

java - 如何在elasticsearch中找出索引创建日期

java - 如何在 Hibernate 中放置自定义类型

java - ViewPager 中同一 Fragment 的多个实例出现问题?

javascript - 既然已经弃用了,我该如何请求增加网络存储配额?