Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Java on Google App Engine without exceeding minute quotas?

A very simple java code inside a doGet() servlet is getting more than a second of cpu time on GAE. I have read some quota related documentation and apparently I am not doing anything wrong.

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

I wanted to know what was using the CPU the most, I use a google help recommendation.

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

The only thing that the code above tells me is that inspecting the header will use more than a second (1000ms) of cpu time, which for Google is a warning on the log panel. That seems to be a very simple request and still is using more than a second of cpu.

What I am missing?


Below the image of the logs for everyone's entertainment. logs for Google App Engine Slow Reports

I am posting the full code, for the benefit of all.

@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");} }
like image 1000
Geo Avatar asked Mar 29 '10 03:03

Geo


People also ask

How many maximum instance hours are supported by an App Engine as free daily usage quota?

Deployments. In each App Engine application, you can deploy up to 10,000 times per day.

Can I use App Engine for free?

App Engine standard environment pricing. Apps in the standard environment have a free tier for App Engine resources. Any use of App Engine resources beyond the free tier incurs charges as described in this section. To estimate costs for App Engine resources in the standard environment, use the pricing calculator.

What are the different ways of storing application data in Google App Engine?

To store data and files on App Engine, you can use Google Cloud services or any other storage service that is supported by your language and is accessible from your App Engine instance. Third-party databases can be hosted on another cloud provider, hosted on premises, or managed by a third-party vendor.


1 Answers

There are no longer any per-minute quotas on App Engine. Any messages referring to them are out of date. If you want to do better profiling of your CPU usage, you may want to try out the newly released appstats for Java.

like image 97
Nick Johnson Avatar answered Nov 03 '22 22:11

Nick Johnson