Memory Bottleneck Analysis of SQL Server Data Page Buffer

Source: Internet
Author: User
Tags server memory

SQL Server caches frequently used data in memory (that is, data page cache) to speed up data access. Because the disk access speed is much lower than the memory, reducing disk access volume is also an important aspect of database optimization.

When there is insufficient memory in the cache area of the data page, slow query and busy disk issues may occur.

Analysis Method: performance counters are mainly used.

View the following performance counters:

1. SQL SERVER: Buffer Manager-Lazy writes/sec: if the memory is insufficient, lazy writer is frequently called to write data to the disk. This value is often not 0.

2. SQL SERVER: Buffer Manager-page life expectancy: When the memory is insufficient, this counter shows a downward trend or stays at a low value.

3. SQL Server: Buffer Manager-page reads/sec: When the memory is insufficient, you do not need to read the disk when querying data that is frequently used but not cached in the memory, this value is sustained or stuck at a high value.

4. SQL SERVER: Buffer Manager-stolen pages: Stolen pages are usually used to cache execution plans for reuse. When the memory is insufficient, the SQL Server mechanism first clears the execution plan cache. This value is displayed as a decrease or a low level.

Query the current user task wait:

CopyCode The Code is as follows: Select * From SYS. sysprocesses

If the memory is insufficient, a large number of async_io_completion wait types are displayed. This is because when memory is insufficient: A. frequent interaction between memory and disk, increased Disk Load B. Data on the disk needs to be read for query and increased Disk Load.

That is to say, at this time the disk also encountered a performance bottleneck, but this is only a "surface", we need to combine multiple performance indicators to identify the root cause is "insufficient memory ".

Determine pressure sources and solutions:

The memory bottleneck related to data page cache is determined through the previous analysis. It is necessary to analyze why this is the case and the solution. It can be divided into the following five aspects:

1. External Pressure

If the OS level or other application services require more memory, Windows will compress the memory size of database pages. The memory pressure comes from the outside. You can check the following performance counters to determine whether they are under external pressure:

1. SQL SERVER: Memory Manager-total Server Memory: the counter value drops.

2. Memory: available Mbytes: this value is reduced to a lower level.

3. If awe or lock page in memory is not used, check process: Private bytes-sqlserver and process: Working Set-sqlserver. The values of both are significantly reduced.

Solution: for non-DB dedicated servers, you must weigh the importance of each application service to allocate memory or increase the memory. Try to make the server run only SQL Server and become a dedicated DB server.

2. SQL Server's own pressure on Database page

When the total server memory has reached the Set max server memory or cannot obtain more memory from the OS, but the amount of frequently accessed data is much larger than the physical memory used for data cache capacity, SQL Server is forced to move memory data into and out to complete the current query.

Observe the following performance counters:

1. The values of SQL server: Memory Manager-total server memory and SQL Server: Memory Manager-target server memory are equal. However, the former is not greater than the latter.

2. There will be a situation described in "analysis method.

Solution: Since SQL server does not have enough memory to store the database page, you can either increase the memory used by SQL Server or reduce the memory used by SQL Server.

Increase: You can add physical memory and enable awe.

Reduction: through horizontal scaling, two or more servers can load part of the database separately, and statements with a large read volume can be optimized.

3. stolen memory pressure in the buffer pool

Under normal circumstances, stolen memory in the buffer pool will not put pressure on database pages. Because database pages is under pressure, lazy writes is triggered, and SQL Server clears the execution plan cache in stolen memory.

However, if the user declares too many objects, but does not log out, and occupies too much memory, the database pages will be compressed. For example: cursor, custom referenced execution plan, etc.

Solution: a) the user-submitted request cannot be completed due to insufficient memory, with a 701 error. B) The user needs to compress the memory of some clers to complete the user request, latency and slowness.

Query the single_pages_kb field of SYS. dm_ OS _memory_clerks to find out which clerks uses too much memory and analyze the cause, and then solve the problem.

4. Multi-page pressure

Multi-page and buffer pool share the virtual address space of the OS. If multi-page uses too much memory, datbase pages will be compressed. The multi-page memory usage is generally small and relatively fixed, and may occur in the following situations:

A. 32-bit SQL server without awe enabled only has 2 GB address space, and the maximum memtoleave extended by the-G startup parameter is used.

B. 64-bit SQL Server calls Memory leakage third-party code.

C. Use a "in" statement with a large number of parameters or a long length

D. Increase the network packet size, which is greater than or equal to 8 KB and has many such connections.

E. A large number of complex XML queries, or third code.

Solution: query the multi_pages_kb field of SYS. dm_ OS _memory_clerks to find out which clerk uses too much memory and analyze the cause, and then solve the problem.

Author: Joe. tj

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.