Programmers of three high: high concurrency, high performance, high availability

First, high concurrency

Brief introduction

High concurrency (High Concurrency) is one of the factors the Internet distributed system architecture design must be considered, it usually means that can simultaneously handle many concurrent requests through the design assurance system. Some commonly used high concurrency-related metrics are response time (Response Time), throughput (Throughput), query rate per QPS (Query Per Second), the number of concurrent users.

  • Response Time: system time response to requests. For example, a system for processing HTTP requests needs to 200ms, the system response time is 200ms.
  • Throughput: the number of requests processed per unit time.
  • QPS: in response to requests per second. In the Internet field, this indicator and throughput distinction is not so clear.
  • Concurrent users: the number of users while carrying the normal use of the system functions. For example, an instant communication system, and represents the number of concurrent users of the online system amount to some extent.

How to improve concurrency

  • Vertical expansion (Scale Up)
    1. Enhanced single hardware performance (Priority): for example: increasing the number of CPU cores, such as core 32, such as Gigabit upgrade the better cards, such as the SSD update better hard disk, such as hard drive capacity expansion 2T, such as system memory expansion 128G.
    2. Single improve performance architecture: For example: Use Cache to reduce the number of IO, using asynchronous service to increase the throughput of a single use lock-free data structures to reduce the response time.
    3. Summary: single tube is to enhance hardware performance, or to enhance the performance of stand-alone architecture, has a fatal deficiency: stand-alone performance is always a limit. So the Internet distributed architecture design of high-level concurrency ultimate solution or extension.
  • Horizontal expansion (Scale Out)
    1. As long as the increase in the number of servers, you can expand the system linearity performance. Horizontal expansion of the system architecture design is required, the difficulty is: how layers are horizontally scalable in architecture.

Second, high-performance

Brief introduction

  1. Simply put, high performance (High Performance) refers to the fast processing speed of the program, accounting for less memory, cpu occupancy rate is low.
  2. High concurrency and high performance are closely related, improve application performance, is certainly improve the system of concurrent capacity.
  3. Application performance optimization time for IO-intensive or compute-intensive and very different, need to be considered separately.
  4. Increase server resources (CPU, memory, number of servers), most of the time can improve concurrency and performance of the application (if the application is capable of supporting multi-task parallel computing, multi-server distributed computing job), but also where to avoid some of the problems, we can better and more efficient use of server resources.

Precautions to improve performance

  1. Avoid the blocking IO allows the CPU is idle, resulting in waste of CPU.
  2. To avoid inter-locks to ensure multi-thread synchronization increase, resulting in a parallel system serialization.
  3. Free to create, destroy, maintaining too many processes, threads, resulting in a waste of resources on the operating system scheduler.
  4. Avoid multiple servers associated with a distributed system, such as: the same depend mysql, program logic using a distributed lock, resulting in a bottleneck in mysql, and distributed into serialized operations.

Third, high availability

Brief introduction

High availability (High Availability) is usually described through a specially designed system, reducing downtime, while maintaining its high availability services (has been able to use).

High Availability Considerations

  1. Avoid single points of: the use of a single server, once the server unplanned downtime, would result in service unavailable
  2. Use the "cluster", a server hung up, there are other backup servers to top

Fourth, for example

Redis master-slave replication

1. scenario

Goods on e-commerce sites, usually once uploaded, numerous views of that professional point of which is "little more than read write."

2. The principle

A Redis service can have multiple copies of the service, this service is called Redis Master, other replication called Slaves.

As shown in the figure, we will decide a Redis server library (Matser), as the other three from the library (Slave), the main library is only responsible for writing data, each data update will update the data synchronized to it all from the library, and is responsible only to read data from the database. As a result, there are two benefits:

  1. Separate read and write : not only can increase the load capacity of the server, and can be freely increased or decreased according to the number of read requests from the library size.
  2. Data is copied has become quite a few, even if a machine fails, you can also use data from other machines fast recovery.

Note : In Redis master-slave mode, a master library can have more than one from the library, but that can only belong to one main library from the library.


PS:

  1. Articles from various resources consolidation, if infringement, please inform deleted.
  2. This article reprint please indicate the source

Guess you like

Origin juejin.im/post/5d821603f265da03c128d011