当前位置:网站首页>Millions of visits - resolution of high concurrency problems
Millions of visits - resolution of high concurrency problems
2022-06-11 01:17:00 【Quiet in the forest, the moon and the immortal】
One 、 Single server + database ( original )
The original architecture
Two 、 Add reverse proxy
Reverse proxy
A proxy is a process of receiving and forwarding requests . Under normal circumstances ,「 Forward agency 」 The object of the proxy is the client ,「 Reverse proxy 」 The object of proxy is the server , It accomplishes these functions :
Health check function , Make sure our server is always running
Routing forwarding function , Forward the request to the correct service path
Authentication function , Ensure that the user has access to the back-end server
Firewall function , Ensure that users can only access the allowed network parts, etc
3、 ... and 、 Introducing load balancer
Introducing load balancer
Reverse proxy has another function : They can also act as load balancers .
Nginx After the configuration , You can reverse proxy multiple servers .
Deployment of multiple stations Nginx( Reverse proxy ), Prevent downtime , Improve the stability of the system .
Nginx Reverse proxy and load balancing configuration reference :nginx Configure the reverse proxy example - Sixi - Blog Garden
Four 、 Extended database
The use of load balancer enables us to distribute load among multiple servers , But now all servers still use a database to store and retrieve data . We can do it the same way , Expand a few more databases , Reduce storage retrieval pressure , But there is a problem of data consistency .
(1) Master-slave mode or single instance write multi copy read
One of the databases is responsible for data writing and modification , Other servers are responsible for reading , The advantage of this scheme is to ensure consistency , Because data can only be written to a single instance database , Then synchronize the written data to other parts , So this scheme is suitable for the situation of reading more and writing less .
I、 How to synchronize ?
Synchronization mechanism
Asynchronous data synchronization by using message queuing , To achieve the final consistency of data . Of course, various exceptions of the message queue will also cause data inconsistency , So we introduced real-time monitoring services , Calculate the data difference between the two clusters in real time , And do consistency synchronization .
II、 The disadvantages of master-slave mode
Master-slave mode architecture
When the main library DB1 When something goes wrong ,DBA Will DB2 Switch to main library , And inform the project team , The project team uses DB2 Replace the original main library DB1, restart web The server , such web The service will use the new master library DB2, and DB1 Will no longer be accessed , The entire database service is restored , etc. DBA Repair DB1 when , then DB1 As DB2 From the library .
There's a big problem here , No matter what happens to the master database or the slave database , Need to be DBA Cooperate with the project team to complete database service recovery , It's hard to automate , And the restoration work is too slow .
So how to make the database highly available ?
High availability HA(High Availability) It is one of the factors that must be considered in the design of distributed system architecture , It usually means , Reduce the time that the system cannot provide service by design .
Database high availability Architecture
As shown in the figure above ,web The server will no longer be directly connected to the main library DB1, It's about connecting KeepAlive A virtual thing ip, Make this virtual again ip Map to main library DB1 On , Simultaneous addition DB_bak Slave Library , Real time synchronization DB1 Data in . Under normal circumstances web Still DB1 Read and write data in , When DB1 After downtime , The script will automatically DB_bak Set as main library , And will virtual ip Mapping to DB_bak On ,web The service will use healthy DB_bak Read and write access as the main library . It only takes a few seconds , Can complete the main database service recovery .
alike ,web The server will no longer connect directly from the library DB2 and DB3, It's about connecting LVS Load balancing , from LVS Connect from library . The advantage of this is LVS Can automatically sense whether the slave library is available , Slave Library DB2 After downtime ,LVS The read data request will not be sent to DB2. meanwhile DBA When you need to add or remove slave nodes , Just operate independently LVS that will do , There is no longer a need for project groups to update configuration files , Restart the server to cooperate .
(2) Operation of sub warehouse and sub table
Reference resources : High concurrent database design - zjone391 - Blog Garden
Problems and solutions to be considered in dividing databases and tables - Simple books
5、 ... and 、 Microservices
Put all the services on one server , In a JAR package , Reduced complexity , But as the scale increases , Things get complicated and inefficient , More developers join in , Develop in the same project code on the same server , There will be more and more conflicts , Interdependence is too high , At the same time, it is not conducive for new developers to read and understand the code .
At this time, the microservice architecture came into being .
Microservice architecture
Each service can be extended separately , Better adapt to needs
The development teams are independent of each other , Each team is responsible for its own microservice lifecycle ( establish , Deploy , to update ) etc. .
Each microservice has its own resources , Like databases , It further alleviates the problem of database .
The division of microservices is mostly based on business , Achieve low coupling .
6、 ... and 、 Caching and content distribution networks (CDN)
Cache architecture
A large part of network applications are composed of static resources , Such as images 、CSS The style file 、JavaScript Scripts and some pages rendered in advance for specific products , By using caching , For some customer requests , It doesn't have to be dealt with all over again , Use the cache , Improve access speed . An enhanced version of caching is called a content distribution network (Content Delivery Network), Massive cache across the world . This allows users to access web content physically close to them , Instead of moving data from the source to users every time .
7、 ... and 、 Message queue
Message queue
Put the customer's task requests into a queue , Carry out management tasks , advantage :
Decoupled the task from the process . Sometimes you have to deal with a lot of pictures , Sometimes very little . Sometimes a large number of services are available , Sometimes it is rarely available . Simply add tasks to your to-do list instead of working on them directly , This ensures that the system remains responsive and that tasks are not lost .
It can be expanded on demand . Starting a large number of services is time-consuming , So start the service when a large number of users upload pictures , It's too late . We add the task to the queue , We can postpone the provision of additional processing capacity .
8、 ... and 、 summary
The greatest truths are the simplest , No matter what plan is adopted , The essence of optimization is to divide and rule , Make a big deal small , Small things become small , There is nothing a middleware cannot solve , If there is , Then add one more !
边栏推荐
- 中国专利奖政策支持介绍,补贴100万
- Introduction to prefix, infix and suffix expressions (code implementation of inverse Polish calculator)
- 2022 recognition requirements for new technologies and new products (services) in Huairou District, Beijing
- Array simulation [queue] and [ring queue]_ code implementation
- Logback log framework
- Store binary tree in sequence [store tree in array]
- 北京密云区高新技术企业培育支持标准,补贴10万
- SSH远程登陆配置sshd_config文件详解
- Beijing Tongzhou District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
- ion_mmap
猜你喜欢

最好的創意鼓工具:Groove Agent 5

用data和proc怎么写出这个,不用sql

云呐|庆远固定资产管理及条码盘点系统

云呐|PDA无线固定资产盘点管理系统

条码固定资产管理系统的作用,固定资产条码化管理

简述自定义注解
![[paper reading] boostmis: boosting medical image semi supervised learning with adaptive pseudolabeling](/img/10/a60cfe830e2238de00121d7bd95ad6.png)
[paper reading] boostmis: boosting medical image semi supervised learning with adaptive pseudolabeling
![[paper reading] fixmatch: simplifying semi supervised learning with consistency and confidence](/img/86/72726f933deef6944b62149759b7d5.png)
[paper reading] fixmatch: simplifying semi supervised learning with consistency and confidence

NVIDIA Jetson之PWM风扇自定义控制

Direct insert sort and shell sort
随机推荐
【VBA脚本】提取word文档中所有批注的信息和待解决状态
北京中国专利奖政策支持介绍,补贴100万
[introduction to ROS] - 03 basic concepts and instructions of ROS
文件“Setup”不存在,怎么办?
About the log traffic monitoring and early warning small project | standardized return of interaction with the database in flask
什么是C端 什么是B端 这里告诉你
[paper translation] recent advances in open set recognition: a survey
Oracle relational tables with XY field values are synchronized to PG database and converted to geometric fields
Controltemplate in WPF
团队管理|如何提高技术Leader的思考技巧?
深圳中国专利奖申报流程介绍,补贴100万
程序员应对压力的几个小窍门
Introduction to the subsidy fund for leading technological innovation of Beijing enterprises, with a subsidy of 5million yuan
最好的创意鼓工具:Groove Agent 5
[introduction to ROS] - 01 introduction to ROS
Sealem Finance打造Web3去中心化金融平台基础设施
快递鸟系统对接
Beijing Mentougou District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
手把手教你前后分离架构(五) 系统身份验证实现
How much is the bonus of China Patent Award, with a subsidy of 1million yuan