java development Performance Tuning

On the whole, for large sites, such as portals, in the face of a large number of user access, high concurrent requests, the basic solution focused on several aspects of this:
1. First need to address the high concurrency network bandwidth and Web requests, We need a reasonable increase server and bandwidth investment, and the need to fully utilize the system software and hardware caching mechanism, will be able to cache content cache memory, reduce stress calculation layer and the storage layer.

2. Second, the need for reasonable stratification of the service server and the service support servers, and distributed and parallel computing algorithms use a large number of calculation processing, and the development process using the Java SDK needs and contracting (Concurrency) for Coding .

3. The storage layer need distributed file server and the storage server column-constructed supporting massive data storage and reading, and also on the deep level relational data configuration parameter optimization.

4. We also need a clear understanding of the future to adjust and optimize the state of the system is running and the platform in different business scenarios gradual.

For large systems, technology uses a very wide scope, from hardware to all areas of software, programming languages, databases, WebServer, firewalls and others have a very high demand. In the face of a large number of user access, high concurrent requests, the basic solution focused on several aspects of this: will use high-performance servers, high-performance database, efficient programming language, as well as high-performance Web container. But in addition to these aspects, not law at all address the high load and high concurrency problems faced, it is necessary to calculate the pressure to offload and load on each computer, using a different server cluster units distributed and parallel computing, the face of pressure generated.

Each specific aspects of some commonly used methods:

First, the application server load balancing 
1, link load balancing 
  by DNS resolve a domain name, the client's access to the IP resolves different, assigned to the different inlets, while ensuring the accessed entry is possible for all possible faster inlet One. 
2, load-balancing software 
  to generate task pages when access is assigned to one of the servers is completed, a process to ensure fair, equitable, on average. We can use the four exchange software commonly used on Linux LVS to solve, LVS is the Linux Virtual Server. 
3, hardware load balancing 

  Fourth exchange using the third and fourth layers of the packet header information, service flow identification section according to the application, the entire traffic flow range segment allocated to the appropriate application server for processing. Application interval of the fourth layer by the exchange terminal and a source IP address, TCP and UDP port joint decision. In the hardware four exchange product areas, there are some well-known products to choose from, such as Alteon, F5, etc.

Latest: CDN acceleration technology. CDN stands for Content Delivery Network. Its purpose is to add a new layer of network architecture in the existing Internet, the content of the site closest to the user posted to the network "edge" so that users can go to obtain the desired content, improve the response speed of the user access to the site .

Second, the image server separation

For a Web server, whether it is Apache, IIS or other containers, the picture is the most resource-consuming, so we need to be separated from the picture page, which is basically a large site strategy will be adopted, they all have independent, even many image server platform. This architecture provides a server system can reduce the pressure of the page access request, and can ensure that the system will not collapse picture problems. On the application server and image server, different configurations can be optimized, for example, can be as little as apache configuration ContentType of support at the time, as little as possible of LoadModule, to ensure higher system consumption and efficiency.


Third, the page optimization 
1, to reduce the number of requests 
  to reduce the number of requests or resource files distributed across multiple domain names to bypass restrictions browser concurrent down-loaded by merging CSS and Javascript files. 
2, compressed CSS and Javascript code. 
  Code to reduce storage space by deleting the contents of the file code line breaks and spaces. 
3, optimizing the picture 
  by picture interception and scaling to optimize picture size, speed up image loading speed. 
4, HTML static 
  use FreeMarker database data into static html files to improve access speed. Applications: For pages that contain does not require real-time content can be used, such as Home, home of the modules news, announcements and more. 

Four, Java optimization design 
1, design patterns 
  singleton, proxy mode, Flyweight, decorator pattern, observer pattern. 
2 cache 
  such as: can be used in conjunction with the AOP Ehcache, the method of doing business layer cache, class name, method name, parameters name as a key, as a result of the object value. Applications: data is not frequently updated, query relatively fixed. 
3, a buffer 
  such as: JDK in the IO package BufferedWriter 
4, multi-threaded 
  Applications: bulk mail, high-volume processing pictures, write the log. Typical consumer producer mode 
5, object pooling 
  , such as: database connection pool C3P0, thread pool Executors, Apache Commons Pool object pool Jakarta 
6, distributed cache 
  Distributed caching framework Terracotta, that enables distributed session, EhCachc to-peer sharing. 

Five, Java program code optimization 
1, String 
  String of replace, substring method have a memory leak problem, replace the split with StringTokenizer methods, charAt method instead of startsWith, endsWith method, StringBuilder replace String and initialized estimated capacity. 
2, List 
  query precedence ArrayList, indels preferentially use LinkedList. If you insert data in the array last, the performance is better than ArrayList LinkedList.

  Traversal implements RandomAccess collection performance of the interface sorted in descending order: Index subscript> iterator> Enhanced for 
3, the Map 
  hashCode method of map objects in the key value determines the performance of the collection. 
4, optimizing the collection of access code 
  when you create a collection object, initialized estimated capacity to improve performance. Instead make use of an internal element method calls. 
5, NIO 
  used to replace the traditional MappedByteBuffer IO to read and write files. 
6, reference 
  can be referenced at the appropriate time with a weak or soft reference buffer implemented, such as: WeakHashMap. 
7, abnormal 
  avoid using exception caught in the loop body. 
8, bit multiplication and division operations instead of

six, to optimize the database 
1, sub-table 
  is divided by a rule table record ID or modulo time dimension. 
2, the partition 
  Oracle database support partition to partition data according to the rules of a column. 
3, the intermediate table 
  the original data to make a series of intermediate processing table according to conceivable target data, the query result from the intermediate table, the intermediate table by the update timing of the timing schedule. Applications: for less demanding real-time data content, such as: data analysis. 
4, historical archives 
  can be drawn based on time to sort out the little-used set of historical data table, the data table leaving only common data, you can use object serialization deserialization to achieve. Applications: little access to historical data. 
5, the column storage 
  MySQL open-source data warehouse Infobright, high compression ratio data storage, query speed can be increased by 5 to 60 times the free version does not support DML statements, does not support high-concurrency, can support more than 10 concurrent queries, you can import data csv file through load . Applications: data is not updated often and less demanding real-time, such as: data analysis. 
6, query cache 
  MySQL Query Cache, Oracle Result Cache, can be achieved by modifying the configuration file database query cache, sql statement as a key, as a result of the way the cache value when the data table changes the corresponding cache will fail. Applications: data is not frequently updated, query relatively fixed. Note: The connection table supports, but does not support function 
7, indexed 
  using more complex sql, large scale data query time, the index can be used to build a manner related to the query field can speed up the search. 
8, sql optimization 
  sql statement, as clear as possible after the select field names instead of * to reduce the query column. Minimize the use of keywords in, and can be replaced by left join exists keyword. 
9, stored procedures, 
  stored procedures compiled only once, Applications: When complex database operations. Such as: multi-table queries, calculations, update. 
10, the database server cluster, separate read and write. 

Seven, JVM tuning. 
1, it is determined heap size (-Xmx, -Xms). 
2, a reasonable allocation of the new generation and the old year (-XX: NewRatio, -Xmn, -XX  : SurvivorRatio).
3, to determine the size of the permanent area (-XX: Permsize, -XX: MaxPermSize  ).
4, select the garbage collector (CMS, G1, etc.), a reasonable set of the garbage collector. 
5, the display disable GC (-XX: + DisableExplicitGC). 
6, disable the recovered metadata category (-Xnoclassgc). 
7, class verification is disabled (-Xverify: none). 
8, JVM memory parameters increase -Xms256M -Xmx1024M -XX: MaxNewSize = 512m -XX  : MaxPermSize = 512m

seven on demand to solve: if demand for module performance bottleneck is dispensable, consider masked this demand. Eight, performance tuning tools  1.JMeter, LoadRunner: performance testing, stress testing. 2.JConsole, JProfiler: monitor heap information, threads, permanent area usage, class loading and so on. 3.Visual VM: troubleshooting, performance monitoring. 




Guess you like

Origin www.cnblogs.com/antines/p/11911521.html