Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A summary of performance optimization

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Personal management

1. Form a systematic thought.

When doing a thing (developing a system, solving a problem), you can start according to a certain system, which can be understood as thinking consciousness. There is less process of starting from scratch, so as to improve efficiency. This matter needs personal long-term summary and rich experience!

2. Broaden your horizons.

Finding your own ideas to solve problems from different aspects and increasing your choice will allow you to weigh more comprehensively and analyze more thoroughly, so that you can understand more deeply and solve problems more effectively. To do technology, you can't just look at technology! A technical bull will have some understanding of history and art.

Technical aspect

1. Code

After getting a performance optimization requirement, many technicians will think about caching, sub-library and sub-table, async, multithreading, JVM optimization and so on. In fact, most of the time you should start with the code. There are many points for code optimization. Here are a few examples:

1. When you already know the list size, specify the list size directly to avoid replication and expansion of the list when the default size is not enough. 2. The location of the variable declaration can be local and non-global, which can effectively avoid taking up memory for a long time and cannot be reclaimed by GC. 3. A large number of variables are declared in the for loop, which consumes memory. Wait.

Therefore, pay more attention to code-level optimization, there is a lot of room for optimization, it is likely that the code will be able to meet the performance requirements after optimization, without the need to increase the number of devices to support traffic!

2. SQL optimization

SQL optimization, I think we can start from five levels.

* the use of SQL sentence optimization keywords like, join, in, exist*SQL index optimization index creation, index size setting * SQL engine optimization according to business needs, select the most suitable engine * database design to optimize my personal cognition, mainly the design of paradigm. Data can be appropriately redundant to reduce database operations. * Database connection pooling optimizes the number of connection pooling monitors and the selection of connection pooling solutions (this piece has not been used by individuals)

3. Cache optimization

Caching is more or less involved in a system. As to what data is put into the cache and what kind of cache is put into it, it is worth considering carefully. There are two personal feelings about the use of caching:

The same data is queried repeatedly in a short period of time and the data is not updated frequently. At this time, you can choose to query from the cache first, and then load the query from the database and set it back to the cache. High concurrency query hot data, the back-end database can not bear the burden.

Type selection consideration:

If the amount of data is small and does not grow and empty frequently (which leads to frequent garbage collection), you can choose the local cache. Specifically, if you need some policy support (such as the eviction policy with full cache), you can consider Ehcache;. If not, consider HashMap;. If you need to consider multi-thread concurrency, you can consider ConcurentHashMap. At present, in terms of resource investment, operation and maintainability, dynamic capacity expansion and supporting facilities, we give priority to Tair. Except for situations that Tair does not currently support (such as distributed locks, Hash-type value), we consider using Redis.

Of course, after using caching, you will face a lot of problems, the biggest of which is data consistency. These can be made according to the needs of the business.

4. Multithreading

In a system, using multithreading can speed up the response time under certain circumstances, such as some asynchronous tasks, just start multithreading to process, and some offline tasks do not need to wait for completion before returning, and so on. However, in situations where online response time is high, multithreading is used as little as possible, especially when the service thread needs to wait for the task thread (many major accidents are closely related to this). You can set a maximum waiting time for the service thread.

Another problem with using multithreading is the complexity of the code. Therefore, it is suggested that if single-machine single-thread can meet business needs, single-machine single-thread can be used as far as possible, if it can not be met, single-machine multi-thread can be used. If still can not be met, then consider multi-machine multi-thread.

When using multithreading, you can consider using thread pools, which have two advantages:

1. Improve performance, save the cost of thread creation and destruction, and save resources. 2. Thread pool can be used to accomplish some functions, such as current restriction. It can ensure the stable handling capacity of the machine under extreme pressure.

5. JVM tuning

JVM is the cornerstone of Java WEB project, and JVM tuning can be carried out according to the characteristics of the project. All I have learned is to adjust some GC recycling mechanisms and strategies. For example, the ratio of Cenozoic to old generation, the ratio of eden to survivor, the threshold ratio of old region that triggers cms recovery, etc. For example, putting big objects into the old age, and so on.

Of course, the road to tuning is long and long. It includes the selection of technology, the use of monitoring, the use of software and even the use of hardware. That's all for today!

For more wonderful content, welcome to follow the official account of Wechat: Java small Notes (ijavanote)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report