Google App Engine for Java的Performance性能问题
Google App Engine - Google Code,会根据负载情况自动关闭或者启动Java web应用的JVM,这使得很多http请求会触发启动JVM并部署web应用,因此这样的http请求非常慢,响应性能很差,用户体验非常差。因为大部分的应用还是需要连接DataStore,那么就需要初始化Data类的MetaData和连接数据库,不可避免需要很多时间。这个问题甚至Google自己也没有很好的办法。
Some requests run slower because App Engine needs to create a new Java virtual machine to service the request. We call that kind of request, a Loading Request. During a loading request, your application undergoes initialization (such as class loading, JIT compiling, etc) which causes the request to take longer. For slow requests which are already close to App Engine's request deadline, the extra initialization can push it past the deadline, causing a DeadlineExceededException. App Engine spins up JVMs on demand, so there are several reasons why you may receive a loading request: You can expect that during the course of developing your application, you will often experience the first two scenarios. In comparison, for a production app receiving even a very small but steady amount of traffic, loading requests are relatively infrequent. You can register an HttpSessionListener in your web.xml which logs from its sessionCreated method. For example: In the future, the Admin Console logs viewer will mark loading requests specifically so that they can be easily identified. App Engine provides high CPU warnings to help you determine which requests might need optimization. In the case of loading requests, though, the execution time is artificially longer due to the extra application initialization required. In addition, the number of loading requests is inversely proportional to the amount of traffic your application receives. So, while your CPU usage due to additional traffic will increase, your CPU usage due to loading requests will decrease. Here are a few suggestions: We've seen this request from some developers with low-traffic applications who'd like to reduce the percentage of loading requests they receive. Although we have many improvements in the pipeline to improve loading request performance, we'd like to gauge the general interest in this feature. If you'd like to be able to reserve a JVM at a price, please star this issue. If there's a particular pricing scheme you're interested in, let us know. We discourage developers from doing this because it increases the average number of loading requests for all low-traffic applications. Instead, we will continue to improve the performance of loading requests for everyone, and you can use the advice on this page to optimize your application's startup performance.What is a loading request?
What causes loading requests?
How do I distinguish normal requests from loading requests in my application logs?
// web.xml snippet
<listener>
<listener-class>
com.example.LogLoadingRequest
</listener-class>
</listener>
// LogLoadingRequest.java
public class LogLoadingRequest implements ServletContextListener {
private static final Logger logger = Logger.getLogger(LogLoadingRequest.class.getName());
public void contextInitialized(ServletContextEvent sce) {
logger.log(Level.INFO, "Loading request occuring.");
}
public void contextDestroyed(ServletContextEvent sce) {
}
}Do I need to be concerned about high CPU warnings in the admin console for my loading requests?
Given that, your time is most often better spent focusing on optimizing other high CPU warnings in relation to your application's total CPU usage.How can I speed up loading requests?
What is Google doing to speed up loading requests?
<precompilation-enabled>true</precompilation-enabled>
In the future, we plan to turn this optimization on for all applications.Can I pay to keep a JVM reserved for my application?
Should I run a cron job to keep my JVMs alive and reduce my loading requests?