Summary of Web application Server performance optimization scheme

Source: Internet
Author: User
Tags message queue dedicated server website performance

Tag:auto    attack         simplify    legend     Architecture    hash Table    mon    get data    

Recently read the "Large Web site technology Architecture ———— Core Principles and Case analysis", summarizes the site application server performance optimization of the section.
Performance optimizations for application servers can generally be started in four directions:

    1. Using the cache
    2. Using asynchronous
    3. Making a server cluster
    4. For code optimization
Application Server performance optimization (i)--caching
I. Using caching to optimize site performance
website Performance optimization First Law: Optimization consider using caching to optimize performance

The essence of caching is a memory hash table, in which the data cache is stored in a memory hash table as a pair of key,value. Caches are primarily used to store data that reads and writes very high and rarely changes.

28 Law: 80% of the accesses fall on 20% of the data.

issues to be aware of using caching:

    1. Put the frequently modified data into the cache. after the data write cache is easy to appear, the application is too late to read the cache, the data is already invalid, and the system burden is increased. Generally speaking, the data read and write more than 2:1, the cache is meaningful.
    2. no access to hotspots. the memory resources used by the cache are very valuable and can only be cached with the latest access to the data, and historical data will be cleaned out of the cache. That is, cache resources should be left to 20% of hot data.
    3. inconsistent data and dirty reads. Typically, the cache is set to expire, and it will reload from the database if it exceeds the expiration time. So the application has to endure a certain amount of time inconsistent data. Another strategy is to update the cache as soon as the data is updated, but this also leads to more overhead and transactional consistency issues.
    4. cache availability. at a certain stage of the business development, the cache will bear the pressure of most data access, the database has become accustomed to the day of the cache, so when the cache server crashes, the database will be unable to withstand such a large amount of stress and downtime, resulting in the entire site is not available. This is known as a cache avalanche, where this failure occurs, or even simply restarting the cache server and the database server to restore site access. Workaround: 1, cache hot standby (when a server goes down, cache access is switched to the hot standby server.) ); 2, cache server cluster .
    5. cache warm-up. the cache is the hotspot data, the hot data is the cache system with LRU to the constantly accessed data filtering out, this process takes a long time. The newly started cache system does not have any data, and the performance and database load of the system are not very good at this time. So you can choose to pre-load the hotspot data when the cache is started.
    6. cache penetration. because of inappropriate business or malicious attacks, persistently high and concurrent access to a nonexistent data, if the cache does not save the data, there will be a large number of requests for pressure on the database. The simple solution is to put the requested non-existent data into the cache, whose value is null.
Second, distributed cache
Distributed Cache Architecture

There are two architectures for distributed cache, one is the distributed cache that needs to update synchronization on the behalf of JBoss cache, and the other is the distributed cache, which is represented by memchached , which does not communicate with each other.

Application Server performance Optimization (ii)--Asynchronous Operation
Using Message Queuing "shaving"

Using Message Queuing to make calls asynchronous can improve the extensibility of your Web site and the performance of your site.
Without the use of Message Queuing, the user's request data is written directly to the database, and in high concurrency, the database is under great pressure and the response latency is exacerbated.
After a message queue is used, the data that is requested by the user is sent back immediately after the message queue, and then by the consumer process of Message Queuing (typically, the process is typically deployed independently on a dedicated server cluster) to fetch data from the message queue and write to the database asynchronously.

Note that with Message Queuing, as data is returned to the user immediately after it is written to the message queue, the data may fail in subsequent operations such as the business check-write database, so the business process needs to be modified appropriately to fit after the business asynchronous processing using Message Queuing.

Anything that can be done later should be done later.

Application Server performance Optimization (iii)--cluster
    • Build a server cluster of multiple servers using load balancing technology for an application
Application Server performance Optimization (iv)--code optimization
One, multi-threaded

Because web site applications are generally managed by the Web server container, the multithreading that the user requests is usually managed by the Web container, but whether it is a Web container-managed thread or a thread created by the application itself, how many threads are appropriate to start on a single server? Assuming that the same type of tasks are performed on the server, there is a simplified way to estimate the number of threads started for that type of task for reference:

number of START processes =[task Execution time/(Task execution Time-io wait time)]xcpu number of cores

The optimal number of boot threads is proportional to the number of CPU cores, proportional to the IO wait time.

Multithreaded programming requires attention to thread safety issues.
The main ways to solve thread safety programmatically are as follows:

    1. The object is designed as a stateless object.
    2. Use local objects.
    3. Use locks when accessing resources concurrently.
Ii. Reuse of resources

There are two main modes of resource reuse: singleton and object pool .
The application of Singleton mode: At present, the main use of anemia mode in web development, from service to DAO are stateless objects, no need to re-build, naturally use a singleton mode.
Object pool: A reusable object instance. In practice, the application's database connection basically uses the connection pooling method. After the database connection object is created, the connection object is placed in the object pool container, and when the application connects, it takes an idle connection from the object pool, uses it, and then returns the object to the object pool without creating a new connection.

Third, data structure

Flexible combinations of various data structures are used.

Iv. Garbage Collection

The JVM is a garbage collection mechanism that divides the available heap space of the application into younger generations and older generations, and divides the young generations into Eden, from and to areas.
If the old generation space is used up, it will trigger the full GC, the so-called total recovery, the full amount of recovery will have a greater impact on the system performance, so should be based on the business characteristics of systems and object life cycle, reasonable set young generation and old Generation size, minimizing full GC.

"Large Web site technology Architecture ———— Core Principles and Case analysis" is a very good book, for inexperienced programmers, is the overall understanding of how to build a large site of a very good science-based books, here Anli.

Reference: "Large Web site technology Architecture ———— Core Principles and Case studies" (HAE)

Summary of Web application Server performance optimization scheme

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.