The three highs of programmers: high concurrency, high availability, and high performance

1. High concurrency indicators

High concurrency is one of the factors that must be considered in the design of Internet distributed frameworks. It can ensure that the system can process many requests in parallel at the same time. For high concurrency, its indicators are:

Response time : The time it takes for the system to respond to incoming requests. For example, it takes 1 second to open a page, then this 1 second is the response time.

Throughput : Throughput refers to how many requests can be processed per second, just like how many grains of rice you can eat per second when you eat.

Second query rate : The second query rate refers to the number of response requests per second, which is similar to the throughput.

Number of Concurrent Users : The number of users who are carrying normal system functions at the same time. For example, in an instant messaging system, the number of simultaneous online users represents the number of concurrent users of the system to a certain extent.

2. Handle high concurrency solutions

1: System Split

        Split a system into multiple subsystems and use dubbo to do it. Then each system is connected to a database, so that there is originally one library, but now there are multiple databases, so that it can resist high concurrency.

2: redis cache

        In most high-concurrency scenarios, there are more reads and fewer writes. Then you can write a copy in both the database and the cache, and then read a lot of caches. After all, redis can easily run tens of thousands of concurrency on a single machine, no problem. So you can consider how to use caching to resist high concurrency in those scenarios that carry the main request reading in the project.

3: MQ (message queue)

        There may still be high-concurrency writing scenarios. For example, in a business operation, you need to frequently engage in database dozens of times, adding, deleting, adding, deleting, and modifying. The high concurrency will definitely cause the system to fail. If you use redis to carry the write, it will definitely not work. , the data will be LRU (eliminate the least frequently used) at any time, the data format is extremely simple, and there is no transaction support.

        Therefore, if you want to use mysql, you have to use mysql and MQ. A large number of write requests are poured into MQ, and you can queue up and play slowly. So you have to consider how to use MQ to write asynchronously and improve concurrency in scenarios that carry complex writing business logic in your project. It is also possible for MQ to resist tens of thousands of concurrency on a single machine.

4: Sub-database sub-table

        Maybe at the end of the database level, it is still unavoidable to resist high concurrency requirements, then split a database into multiple libraries, and multiple libraries can resist higher concurrency; then split a table into multiple tables, each table Keep the amount of data a little less to improve the performance of SQL running.

5: Read and write separation

        This means that most of the time, the database may read more and write less. It is not necessary to concentrate all requests on one library. You can set up a master-slave architecture, write to the main library, read from the library, and separate reading and writing. When there is too much reading traffic, you can add more slave libraries.

2. High performance

1. What is high performance?

        High performance means that the program processing speed is very fast, occupies less memory, and has low CPU usage. High-performance indicators are often closely related to high-concurrency indicators. If you want to improve performance, you must improve the system's concurrency capabilities, and the two are tied together. When optimizing application performance, there is still a big difference between computing-intensive and IO-intensive, which need to be considered separately. It is also possible to increase the number of servers, memory, IO and other parameters to improve the concurrency and performance of the system, but do not waste resources. Only by considering the highest utilization rate of the hardware can it be maximized.

2. How to improve performance?

Avoid idle CPU due to IO blocking, resulting in waste of CPU

Avoid adding locks between multiple threads to ensure synchronization, resulting in serialization of parallel systems

Avoid creating, destroying, and maintaining too many processes and threads, causing the operating system to waste resources on scheduling

(1) Use bitmaps to improve query performance

(2) Use Bloom filter to solve cache penetration.

(3) Current limiting algorithm counter: redis can implement sliding window algorithm, leaky bucket algorithm and token bucket can both be implemented through message queues. Although google's Guawa can implement current limiting, single machine current limiting cannot be achieved in a distributed environment Purpose.

(4), RocketMQ performance improvement method.

(5), redis master-slave replication, sentinel mode, cluster

(6), mysql read and write separation: binlog log, sub-database and sub-table, problems caused by sub-database and sub-table

(7) Reliability of the message queue: producers send retries, message queues are copied synchronously, disks are asynchronously flushed, consumers retry consumption, go to the dead letter queue, repeat consumption, and add a deduplication table. Insert the deduplication table first each time.

(8), multi-level cache

(9), circuit breaker downgrade, sentinel circuit breaker downgrade strategy slow down with abnormal ratio abnormal number

            Flow control: QPS flow control directly rejects warm up queues at a constant speed.

            In the advanced settings, there are current limiting based on the caller, link current limiting, only requests from a specific link, associated current limiting, and frequent writing operations, limiting the current flow of read operations. Sentinel is used in the production environment.

3. High availability

1. What is high availability?

        High availability usually describes a system that has been specifically designed to reduce downtime while maintaining high availability of its services. High availability Note that if you use a stand-alone server, once it hangs up, the service will be unavailable. You can use a cluster instead of a stand-alone server. If one server hangs up, there are other backup servers that can take over. Or use a distributed deployment item.

2. Highly available cluster solution for redis

         Redis single copy

         Redis multiple copies (master-slave)

         Redis Sentinel (Sentinel)

         Redis Cluster

         Redis self-developed.

 

Guess you like

Origin blog.csdn.net/weixin_46048259/article/details/128491043