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

What problems can be solved by the separation of read and write from database?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Database read-write separation can solve what problem, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Some technical students may not know much about "read-write separation" and think that the load problem of the database can be solved by "read-write separation".

This is actually a very big misunderstanding. If we want to use "read-write separation", we should first understand what kind of problem "read-write separation" is used to solve, rather than just using this technology.

What is the separation of reading and writing?

In fact, the database is divided into master and slave libraries, one master library is used to write data, multiple slave libraries complete the operation of reading data, and the master and slave libraries synchronize the data through some mechanism, which is a common database architecture.

A group synchronizes from a cluster, which is often referred to as a "grouping".

What problems does the database grouping architecture solve?

Most Internet businesses tend to read more and write less. At this time, the reading of the database will first be called the bottleneck of the database. At this time, if we want to linearly improve the read performance of the database, eliminate read-write lock conflicts to improve the write performance of the database, then we can use the "grouping architecture" (read-write separation architecture).

To sum up in one sentence, read-write separation is used to solve the read performance bottleneck of the database.

However, not any read performance bottleneck requires read-write separation, and there are other solutions.

In Internet application scenarios, there are often large amount of data, high concurrency, high availability and high consistency. If you use "read-write separation", you need to pay attention to these problems:

Database connection pool should be distinguished, which is read connection pool and which is write connection pool, which will increase the difficulty of research and development.

In order to ensure high availability, the read connection pool should be able to achieve automatic failover

The consistency of master and slave needs to be considered.

With so many issues to consider, if we are just trying to solve the "bottleneck of database reading", why not use caching?

Why use caching?

Caching is also a kind of architecture that is often used in the Internet. unlike "read-write separation", read-write separation shares the reading pressure of the database through multiple read libraries, while storage is through the use of cache. reduces the pressure on database reading. There is no substitute for the other, but if there is a choice between read and write separation of the cache, caching should be considered first.

Why?

The cost of using the cache is much less than that of the slave library.

Cache development is relatively easy, most of the read operations can be cached first, and then infiltrated into the database if you can't find it.

Of course, if we have used caching, but read is still a bottleneck, we can choose the "read-write separation" architecture. To put it simply, we can think of read-write separation as a solution when caching cannot be solved.

Of course, caching is not without its shortcomings.

For caching, we have to consider the high availability, otherwise, if the cache fails and all the traffic is gathered on the database at the same time, then the database will definitely fail.

What are the common database bottlenecks?

In fact, it is the bottleneck of data capacity. For example, in order tables, the amount of data only increases, and historical data must be retained, which can easily become a performance bottleneck, but in order to solve such database bottlenecks, "read-write separation" and caching are often not suitable. What is the most suitable?

Database horizontal segmentation

What is database horizontal sharding?

Database horizontal segmentation, which is also a common database architecture, is a framework that divides the database through algorithms. A horizontal sharding of each database in a cluster is often referred to as a "shard". The data in each shard does not coincide, and the data in all shards are combined to form all the data.

What problem does the horizontal segmentation architecture solve?

In most Internet services, the amount of data is very large, and the capacity of a single database is the most likely to become a bottleneck. When the capacity of a single database becomes a bottleneck, we want to improve the write performance of the database and reduce the capacity of a single database, we can use horizontal segmentation.

On the other hand, a small number of programmers rashly use "read-write separation" without analyzing what the performance bottleneck of the database is, but do not realize that "horizontal segmentation" is the right way.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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