Domanda

Un codice Java molto semplice all'interno di un servlet doGet () è sempre più di un secondo di tempo di CPU su GAE. Ho letto un po 'di documentazione relativa quota e apparentemente non sto facendo niente di male.

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

Volevo sapere cosa stava usando la CPU più, io uso una raccomandazione Guida di 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);

L'unica cosa che il codice di cui sopra mi dice è che l'ispezione l'intestazione utilizzerà più di un secondo (1000 ms) di tempo di CPU, che per Google è un avvertimento sul pannello di registro. Che sembra essere una richiesta molto semplice e ancora sta usando più di un secondo di CPU.

Quello che mi manca?


Sotto l'immagine dei registri per il divertimento di tutti. registri per Google App Engine Report lento

Vi metto il codice completo, a beneficio di tutti.

@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");} }
È stato utile?

Soluzione

Non ci sono più le quote per-minuto su App Engine. Tutti i messaggi ad essi non sono aggiornati. Se si vuole fare una migliore profilazione del vostro utilizzo della CPU, si consiglia di provare il recente rilasciato appstats per Java .

Altri suggerimenti

I registri mostrano che è lento solo qualche volta.

è la costruzione del vostro oggetto servlet molto lento?

  

L'unica cosa che il codice di cui sopra mi dice è che l'ispezione l'intestazione utilizzerà più di un secondo (1000 ms) di tempo di CPU, che per Google è un avvertimento sul pannello di registro. Che sembra essere una richiesta molto semplice e ancora sta usando più di un secondo di cpu.

Questo accade anche senza le chiamate alle API di quote?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top