High Concurrency System Optimization Ideas

Hardware and operating system level optimization:

1. Improve hardware performance, use multi-core CPU, increase memory, and solid-state hard disk. Note that 32-bit system memory is limited to 2G, and 64-bit has no such limit.

2. Add cluster load balancing for application services, hardware load F5, soft load LVS, Nginx to limit current

3. The request data is separated from static and dynamic. If you access static resources such as static pages and pictures, you can route them to a fixed path through Nginx, without accessing the background server, reducing server pressure

Application system architecture optimization:

1. In the early stage of system design, scalability should be considered, and distributed, and a good balance should be obtained between the three CAPs, and an efficient RPC communication framework (dubbo, thrift) between distributed applications should be selected;

2. Pay attention to the high-availability design of the system, prevent single point of failure, do a good job of service fault tolerance (failback/failover/failfast/failsafe), and do a good job of filing during peak traffic times, such as service downgrade, dynamic server expansion, dual-system hot backup, etc.

3. Do a good job of application splitting to prevent a large number of functions from being unavailable due to application downtime, and adopt different deployment strategies for applications with different traffic volumes

4. Use cache to reduce access to the database, and put data that is frequently used and changed in the cache. Stand-alone cache or distributed cache can be used, and technology selection ehcache or memcached, redis, etc. In order to improve the cache hit rate, the user request can be hashed consistently according to the user ID to ensure that every time the same user request is sent to the same server

5. Multi-core CPU system can use multi-threading and thread pool to speed up system processing speed

6. Reasonable use of message middleware in distributed systems to do application decoupling, traffic shaving peaks and valleys (rocketmq pull mode to pull data), final consistency of distributed things, etc.

Coding conventions and JVM optimizations:

1. Select a suitable garbage collector according to the characteristics of the application. For example, if high throughput is required, use Parallel Scanvenge. If you need to improve the response speed, use CMS or G1 collector. Set a reasonable JVM size and garbage removal trigger point according to the size of the traffic. etc

2. Pay attention to the use of java classes in high-concurrency environments to consider thread safety. You can choose thread-safe containers such as ConcurrentHashMap, CopyOnWriteList, or make reasonable use of lock mechanisms, such as synchronized, reentrantLock, reentrantReadWriteLock, etc. Distributed environments even need to use distributed locks, you can use Redis, zookeeper and other implementations, pay attention to the support of locks for interruption, sharing, and timeout

3. Reduce the holding time of locks, and try to acquire locks in the same order by multiple threads to avoid deadlocks;

4. Use the thread pool reasonably to reduce the overhead of thread creation and destruction, but it is not that the more threads, the faster the number of CPUs +1; CPU time utilization

Database optimization:

1. Adopt a good database architecture design, such as read-write separation, horizontal splitting, and vertical splitting; read-write separation and vertical splitting are multi-data source problems, and the splitting rules can be region, business occurrence time, business type, etc. , can be implemented by data access layer middleware or AOP+Annotation; horizontal splitting pay attention to splitting rules, you can use user ID, account ID, etc. for splitting, pay attention to avoid multi-database joint query, distributed things, etc. When designing tables, some data redundancy is carried out. For example, the transaction table stores some necessary information of customers, and the public tables such as permissions and routing tables are copied in each database.

2. Use cache reasonably, for example, Mybatis enables first-level and second-level caches, reduces database access, enables preparedStatement, and reduces runtime SQL precompilation overhead

3. Precautions for sql writing and use: ① Reasonable use of indexes (single index, joint index, too many will affect the speed of table insertion and deletion, jion column uses index) ② Minimize the use of statements that make the index invalid. For example: like '%', Or, splicing in sql, using calculation functions in sql, etc.; 3. Multi-table query uses small tables to drive large tables; 4. select only returns the required items

4. Adopt high-availability distributed transaction solutions, such as: 2pc (high network requirements, high system load under high concurrency, low efficiency), flexible things (sending transaction messages through rocketmq to achieve final data consistency)

Good operation and maintenance:

1. Do a good job in the record of the flow meter and log collection, record the transaction element items and the server ID of the transaction access in the flow meter, so as to facilitate the viewing of the log;

2. Establish a good security early warning mechanism. If there is a problem, it will automatically prompt the relevant person in charge by email or text message, so as to follow up in time

3. Do a good job in disaster preparedness, switch between active and standby, and deploy in multiple places

Use of new technologies:

1. Adopt micro-service architecture to decouple applications, and applications do not affect each other, improve system availability,

2. Docker container technology solves the problem of inconsistent production and test environments, and achieves dynamic expansion and rapid deployment of server clusters through dynamic deployment and unloading of containers.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324421939&siteId=291194637