Gae Java application performance optimization

Source: Internet
Author: User
Gae Java application performance optimization

Reprinted by the author:

By: 88250

Date: January 1, February 8, 2011

 

This article describes the performance optimization experience of Gae application development. It mainly introduces how to design and optimize high-performance Gae applications in terms of framework, cache, and asynchronous calling.

TOC

Use memcache for caching

HTML page

Data query results

Memcache usage notes

Reduce memory usage

Try to avoid using the framework

Stateless Design

Asynchronous APIs

Others

Static Resources

Entity Group

Domain name resolution

Implementation Logic

References

Use memcache for caching

Cache is used to increase the response speed.

HTML page

Pages can be cached by function. For more information, see apply memcached to improve site performance-Reduce read from databases and data sources.
.

You can also cache the entire page to simplify the cache and template processing logic.

Data query results

If you directly use Gae datastoreservice
To query data, it is necessary to cache the query results:

  • Single Entity
    The object to be queried based on the unique identifier.
  • Set entity
    Objects that are queried Based on the Combined Query conditions, such as paging results.
Memcache usage notes
  • Calling Gae memcache also consumes a certain amount of CPU (serialization/deserialization is required)
  • Use Gae memcaheservice # clearall ()
    Method to clear the cache of all namespaces
Reduce memory usage

The main purpose of reducing memory usage is to make full use of the limited memcache service and reduce the instance startup time.

Try to avoid using the framework

Although some popular Java Web frameworks (Spring, struts, and play! , Etc) can run on gae, but if you want to use Gae for free,

It is better not to use the existing framework, because most frameworks:

  • Not specifically designed for Gae
  • Memory consumption
  • Will extend the start time

In addition, we will not discuss the advantages and disadvantages of JSP and other template engines here. Currently, the test shows that freemarker and JSP have very similar performance without page buffering.

Stateless Design

Stateful design is more memory-consuming. It is better for the server to use less stateful models unless it is necessary to process complex business logic (such as multi-step forms and advanced search ).

Asynchronous APIs

Gae provides asynchronous versions of Apis such as data access and HTTP requests. Note:

  • Currently, the query in Gae/J (1.4.0) does not have asynchronous APIs.
    Asyncdatastoreservice
    Or datastoreservice
    Use preparedquery. asiterable ()
    And preparedquery. asiterator ()

    The results are the same. If they are all called, they are returned and the data is actually obtained during iteration.
  • Blocking (synchronization) Point
    When asynchronous APIS is called, pay attention to the point at which the code block is synchronized. Premature synchronization will reduce the advantages of asynchronous APIs.
  • Calling asynchronous APIs consumes the same quota as calling synchronous APIs.
Others
Static Resources

Carefully configure the <static-files> element in the appengine-web.xml, which will be retrieved from a separate Google server, cache, not occupying

Application Server quota.

Entity Group

An entity group is an entity set that is logically related and stored in the same Gae cloud storage region. Transaction operations can only be performed on objects in the same entity group.

Entity groups have a certain impact on performance (it has not been proved by practice), but try to minimize the impact of entity groups.

Domain name resolution

The second-level domain name (* .appspot.com) sent by Gae is very unstable in China, so it is best to bind your own domain name.

However, you need to configure the ghs ip address when binding a domain name. Currently, no IP address is available in China. Further, you need to configure a reverse proxy for request proxy.

After the server performance is optimized, You need to select a fast and stable reverse proxy. Otherwise, the hard work in the server to reduce the processing time of hundreds of MS,

The result is completely consumed on the route and packet loss.

If the free reverse proxy does not meet the performance requirements, you can only pay for it yourself, or wait until GHS is available ....

Implementation Logic

In addition, Gae currently provides a relatively small free CPU quota, so it is critical to optimize the implementation logic to reduce CPU usage and APIs usage.

When writing code, you should always pay attention to whether the logic of the Code is concise enough. parameters that can be obtained at one time should not be obtained repeatedly. The obtained parameters are passed in the form of method parameters.

References
  • App Engine Java Overview
  • Best practices for writing scalable applications
  • Gae SDK javadoc
  • Gae data storage-Transactions
  • Gae/Java application framework -- b3log latke

 

This article uses b3log solo
From simple design to ghost Art
The original address for Synchronous publishing: http://88250.b3log.org/gae-java-performance-optimization.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.