In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the database load reduction methods". In the daily operation, I believe that many people have doubts about the database load reduction methods. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what are the database burden reduction methods?" Next, please follow the editor to study!
1. Caching
The first solution is caching.
Cache, in which we can cache data directly, such as Map, or use a cache framework such as Redis to store some hot data that need to be used frequently in the cache, and return the data in the cache directly to the user whenever the user accesses it, which can effectively reduce the pressure on the server.
The data that can be cached and used generally can not be too high on real-time requirements.
two。 Page static
Page static can actually be regarded as another form of caching, which is equivalent to caching the relevant page rendering results directly. First of all, as you know, in our Web project, resources are divided into two main categories:
Static resources
Dynamic resources
Static resources are our common HTML, CSS, JavaScript, pictures and other resources, these resources can be directly returned to the front-end browser without server processing, and the browser can directly display them.
Dynamic resources refer to the Servlet interfaces, Jsp files, Freemarker and so on in our project, which need to be rendered by the server before returning to the front-end resources.
In actual projects, the access speed of static resources is much higher than that of dynamic resources, and dynamic resources are often prone to server bottlenecks and database bottlenecks. Therefore, for some pages that are not updated frequently, or pages that update slowly, we can save a dynamic resource as a static resource through the static page, so that when the server needs to access it, we can directly return the static resource. You can avoid manipulating the database and reduce the pressure on the database.
For example, in an e-commerce project that Brother Song did before, the system automatically counted out the hot items that users are currently searching for according to big data's statistics. These hot items are updated every 10 minutes, that is to say, within 10 minutes, users log in and see the same hot products. Then there is no need to query the database every time, but the page of hot data is automatically written to the server through the output stream and written into an ordinary HTML file, and the next time the user visits it, within the validity period of 10 minutes, the HTML page is returned directly to the user, so there is no need to operate the database.
Generally speaking, Freemarker, Velocity and other related methods can help us quickly generate dynamic pages into static pages.
This is the static page.
3. Database optimization
Many times the program runs slowly, not because the equipment is backward, but because the database SQL is poorly written.
In order to solve the problem of massive data, database optimization must be inevitable. Generally speaking, we can optimize the database from many aspects, such as SQL optimization, table structure optimization, database partition and table partition and so on. In fact, database optimization is also a huge knowledge. Brother Song will have time to write a serial and talk about this topic carefully.
4. Hot spot data separation
Although the data in the database is a huge amount of data, it can not be seen that all the data are active data, such as user registration, some users disappear without a trace after registration, while some users keep logging in, therefore, for these two different users, we can separate the active users and save only the active user data in the data table of the main operation. Every time the user logs in, first go to the main table to see if there is a record, if so, log in directly, if not, then check other tables.
By judging the number of logins of the user in a certain period of time, the hot spot data can be quickly separated.
5. Merge database operation
The purpose of this solution is to reduce the number of database operations, such as multiple insert operations, which can be merged into a single SQL. Multiple queries with different conditions, if conditions permit, can also be merged into one query to minimize the operation of the database, reduce consumption on the network, and reduce the pressure on the database.
6. Database read-write separation
In fact, Song GE also talked to everyone in the previous MyCat (MyCat series). After reading and writing separation, on the one hand, it can improve the operational efficiency of the database, on the other hand, it can be regarded as a backup of the database. For the specific operation of this piece, you can refer to Brother Song's previous article.
7. Distributed database
After the separation of database read and write, it virtually increases the complexity of the code, so it is generally necessary to use distributed database middleware, which can effectively improve the flexibility of the database and easily expand the capacity of the database at any time. At the same time, it also reduces the coupling of the code.
8.NoSQL and Hadoop
In addition, introducing NoSQL and Hadoop is also one of the solutions. NoSQL breaks through the definition of table structure and fields in relational database, so that users can operate flexibly and conveniently. In addition, through the characteristics of storing data in multiple storage blocks, NoSQL naturally has the advantage of operating big data. However, to be honest, NoSQL is still common in Internet projects and rare in traditional enterprise applications.
Needless to say Hadoop, big data deals with sharp weapons.
At this point, the study of "what are the ways to reduce the burden of database" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.