Очень простой Java-код внутри сервлета doGet () получает больше секунды процессорного времени на GAE. Я прочитал некоторую документацию, связанную с квотами, и, очевидно, я не делаю ничего плохого.
//Request the user Agent info
String userAgent = req.getHeader("User-Agent");
Я хотел знать, что использует процессор больше всего, я использую рекомендацию справки 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);
Единственное, что говорит мне приведенный выше код, это то, что при проверке заголовка будет использоваться более секунды (1000 мс) времени процессора, что для Google является предупреждением на панели журнала. Это кажется очень простым запросом и все еще использует больше секунды процессора.
Чего мне не хватает?
Ниже изображения бревен для всеобщего развлечения.
Я выкладываю полный код на благо всех.
@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");} }