A civilian application performance optimization Checklist (complete) — turn

Original address: http://calvin1978.blogcn.com/articles/checklist.html

1. General principles

Some correct but slightly nonsense principles can guide the optimization of each subsequent chapter, so I still have to be wordy once.

2. Environmental preparation

Ensure compliance with your own specifications (if not, go home and write one), especially the configuration of offline pressure test server should be consistent with the production environment.

2.1 operating system

2.2 JVM and application server

2.3 peripheral dependent system

2.4 background auxiliary program

2.5 test procedure

2.5 flow model

Everyone has such a general model in mind, but they rarely write it seriously.

At this point, you can probably feel the style of this checklist, which is understood by everyone, but may be forgotten for a while. Let's write it down in detail here.

3. Database

Special thanks, our DBA.

3.1 topology

According to the principle of expansibility:

3.2 Schema

Their own specifications shall include:

3.3 sql

1. Own specifications shall include:

Design SQL according to the principle of minimizing data and interaction:

According to the principle of scalability, put the load on the application service instance that is easier to scale:

2. Contact DBA to review the slow query of MySQL statistics. Try to avoid the extra column when parsing the SQL query plan: using file sort, using temporary

3.4 Dao framework

3.5 affairs

Connection pool

Model selection:

Configuration of connection pool:

When dividing databases and tables, we can consider secondary development based on hikaricp, reduce the total number of idle connection inspection threads (for example, 128 partitions, there may be 256 threads), reuse the connection of libraries on the same instance, etc.

4. Cache

4.1 multi level cache

Use the above conditions to select an appropriate cache scheme, or use multi-level cache at the same time to return to the source layer by layer.

4.2 overview

4.3 in heap cache

Model selection:

GuavaCache:

4.4 off heap cache

Model selection:

4.5 Memcached

client:

Data structure:

4.6 Redis as Cache

Redis topology:

Based on the principle that point-to-point communication is better than gateway, the following two topologies are used

Server:

client:

Data structure:

Command:

5. Service call

5.1 interface design

1. The principle of minimizing interaction:

It supports batch interface and maximum batch. It comprehensively considers the needs of the caller and the capacity of back-end storage.

It supports coarse-grained interfaces. While supporting atomic fine-grained interfaces, it also supports coarse-grained interfaces / aggregation layer interfaces to combine the acquisition of multiple data sources and multiple actions into one coarse-grained interface.

2. The principle of minimizing data:

While providing a large interface that returns all data, it also provides a lightweight interface that only meets the needs of some callers.

It is better to provide an interface that can customize the return field.

3. Binary data is better than text data

It is also a simple and versatile choice with performance, especially when there is a large amount of data.

5.2 RESTful

Taking Apache httpclient as an example, most restful frameworks encapsulate Apache httpclient.

In addition, okhttp is also worth seeing.

5.3 own RPC framework

Each RPC framework has different characteristics, but the considerations are similar.

6. Message asynchrony

6.1 type selection

6.2 Kafka

6.3 RabbitMQ

7. Log

7.1 general

7.2 contents

7.3 asynchronous log

8. Tools

8.1 JSON

FastJson:

Jackson:

8.2 binary serialization

Pb and thrift that need to define IDL, kyro that does not need to define storm, etc. can be selected, and others are old.

8.3 bean replication

When copying between VO and Bo, use orika (code generation) or dozer (CACHE reflection), instead of Apache beanuitls and spring BeanUtils that need reflection every time.

8.4 date

The conversion between date classes and strings in JDK is slow and non thread safe.

Continue to use Java dates. If you don't want to make a big move, use the fastdateformat of commonslang.

You can use joda time or jdk8's new date API for big actions.

9. Java code optimization and business logic optimization

Reference to optimize memory usage, concurrency and locking.

The rule is preceded by the operation that consumes a lot. If the previous conditions are not met, you can.

In addition, the principles mentioned above, such as caching as much as possible, interaction as little as possible, data as little as possible, parallelism, asynchrony, etc., can be used here.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>