当前位置:网站首页>MySQL combat optimization expert 12 what does the memory data structure buffer pool look like?

MySQL combat optimization expert 12 what does the memory data structure buffer pool look like?

2022-07-06 10:07:00 Office template library material frog

1、 How to configure your Buffer Pool Size ?

First let's take a look , How should we configure your Buffer Pool How big is it ?

because Buffer Pool The essence is actually a memory component of the database , You can understand it as a piece of memory data structure , So this memory data structure must be Have a certain size , It can't be infinite .

This Buffer Pool By default 128MB, It's still a little small , Under the actual production environment, we can completely Buffer Pool Adjustment .

For example, if our database is 16 nucleus 32G Machine , Then you can give Buffer Pool Assigned 2GB Of memory , Just use the following configuration .

[server]

innodb_buffer_pool_size = 2147483648

If some friends don't know where the configuration file of the database is and how to modify its configuration , The suggestion is to search some on the Internet first MySQL Go to the introductory materials have a look , In fact, this is the most basic and simple .

Let's first look at the following figure , There are pictures in the database Buffer Pool Memory components .

                                                                                                                                                        

2、 Data pages :MySQL A unit of data abstracted from

Let's move on to the next question , Suppose that there must be a memory area in our database now Buffer Pool 了 , So how do we put our data in BufferPool Medium ?

We all know that the core data model of the database is the table + Field + The concept of line , In other words, we all know that there are tables in the database , A watch has many words paragraph , Then there are many rows of data in a table , Each row of data has its own field value . So we think our data is placed line by line in Buffer Pool Inside Do you ?

This is obviously not , actually MySQL The concept of a data page is abstracted from the data , He put many rows of data in one data page , That is to say, I There are many data pages in your disk file , There are many lines of data in each page , As shown in the figure below .

             

So in fact, suppose we want to update a row of data , At this time, the database will find the data page where this row of data is located , Then from the disk file, put the data page where this line of data is located Load directly into Buffer Pool In go to

in other words ,Buffer Pool There are data pages stored one by one , Here's the picture .

             

3、 Data pages on disk and Buffer Pool How do the cached pages in correspond ?

In fact, by default , The size of the data pages stored on the disk is 16KB, in other words , One page of data contains 16KB The content of .

and Buffer Pool One data page after another stored in , We usually call it cache page , Because after all Buffer Pool It's a buffer pool , The data inside is from the magnetic Disk cache to memory .

and Buffer Pool By default , The size of a cache page corresponds to the size of a data page on the disk , All are 16KB.

So let's look at the following figure , I give the Buffer Pool Marked out his memory size , Suppose he is 128MB Well , Then the size of the data page is 16KB.

 

4、 What is the description information corresponding to the cache page ?

Then we need to understand the next concept , For each cached page , He actually has a descriptive message , This descriptive information can generally be considered to describe this slow Page saved

For example, it contains some of the following things : The table space to which this data page belongs 、 The number of the data page 、 This cache page is in Buffer Pool The address in and some other miscellaneous Eight things .

Each cache page corresponds to a description , The description information itself is also a piece of data , stay Buffer Pool in , The description data of each cache page is placed at the top , Then each cache page is placed at the back

So now let's look at the following figure ,Buffer Pool It actually looks like this .

                                                                                                                                                             

And here we should pay attention to one thing ,Buffer Pool The description data in is roughly equivalent to the size of the cache page 5% about , That is, each description data is about 800 A word Section size , Then suppose you set buffer pool Size is 128MB, actually Buffer Pool The real final size will exceed some , There might be a 130 many MB The appearance of , Because it also stores the description data of each cache page .

5、 Today's question

Today I want to leave you to think about a problem , Is the problem of memory fragmentation

You can imagine , about Buffer Pool for , It will store many cache pages and corresponding description data , So suppose Buffer Pool In the memory It's all used up , There is not enough memory left to store cached pages and description data , here Buffer Pool Is there no memory in it ? Still say Buffer

Pool There will be some memory fragments left in the ?

If you think Buffer Pool If there are memory fragments in the , So what do you think should be done to minimize Buffer Pool Memory fragments in ?

原网站

版权声明
本文为[Office template library material frog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060907389294.html