SQL Cached Queries Test

SQL Server maintains a cache, but not with canned results for queries. In an OLTP system, many tables are frequently updated; it is therefore highly unlikely that the same query yields the same result twice. Similarly, the likelihood of the same query reappearing with exactly the same parameters is also very less. What SQL Server stores in its cache therefore, are  recently accessed data pages, as well as query plans for recently submitted queries and invoked stored procedures. This makes it possible to retrieve the result of a query without accessing the disk for frequently accessed tables. Too few queries in the cache means more direct disk accesses! To minimize reads/writes to physical disks, more number of queries should execute in the cache. Using this test, you can determine the number of queries that are currently executing in the cache and also figure out the impact of cache misses on the physical disks. These metrics reveal whether/not cache usage is at a desired level. In the process, the test also measures the resource usage of and the I/O activity generated by the cached queries and sheds light on time-consuming, resource-intensive and I/O-intensive queries that are executing in the cache.

Target of the test : A Microsoft SQL server

Agent deploying the test : An internal agent

Outputs of the test : One set of results for every Microsoft SQL server monitored

Configurable parameters for the test
  1. TEST PERIOD - How often should the test be executed
  2. Host – The IP address of the Microsoft SQL server.
  3. Port - The port number through which the Microsoft SQL server communicates. The default port is 1433.
  4. ssl – If the Microsoft SQL server being monitored is an SSL-enabled server, then set the ssl flag to Yes. If not, then set the ssl flag to No.
  5. instance - In this text box, enter the name of a specific Microsoft SQL instance that is to be monitored. The default value of this parameter is “default”. To monitor an Microsoft SQL instance named “CFS”, enter this as the value of the INSTANCE parameter.
  6. USER – If a Microsoft SQL Server 7.0/2000 is monitored, then provide the name of a SQL user with the Sysadmin role in this text box. While monitoring a Microsoft SQL Server 2005 or above, provide the name of a SQL user with all of the privileges outlined in User Privileges Required for Monitoring Microsoft SQL server.

  7. password - The password of the specified user
  8. confirm password - Confirm the password by retyping it.
  9. domain - By default, none is displayed in the DOMAIN text box. If the ‘SQL server and Windows’ authentication has been enabled for the server being monitored, then the DOMAIN can continue to be none. On the other hand, if ‘Windows only’ authentication has been enabled, then, in the DOMAIN text box, specify the Windows domain in which the managed Microsoft SQL server exists. Also, in such a case, the USER name and PASSWORD that you provide should be that of a user authorized to access the monitored SQL server.
  10. isntlmv2 - In some Windows networks, NTLM (NT LAN Manager) may be enabled. NTLM is a suite of Microsoft security protocols that provides authentication, integrity, and confidentiality to users. NTLM version 2 (“NTLMv2”) was concocted to address the security issues present in NTLM. By default, the isntlmv2 flag is set to No, indicating that NTLMv2 is not enabled by default on the target Microsoft SQL host. Set this flag to Yes if NTLMv2 is enabled on the target host.
  11. ISPASSIVE – If the value chosen is yes, then the Microsoft SQL server under consideration is a passive server in a SQL cluster. No alerts will be generated if the server is not running. Measures will be reported as “Not applicable" by the agent if the server is not up.
  12. DETAILED DIAGNOSIS – To make diagnosis more efficient and accurate, the eG Enterprise embeds an optional detailed diagnostic capability. With this capability, the eG agents can be configured to run detailed, more elaborate tests as and when specific problems are detected. To enable the detailed diagnosis capability of this test for a particular server, choose the On option. To disable the capability, click on the Off option.

    The option to selectively enable/disable the detailed diagnosis capability will be available only if the following conditions are fulfilled:

    • The eG manager license should allow the detailed diagnosis capability
    • Both the normal and abnormal frequencies configured for the detailed diagnosis measures should not be 0.
Measurements made by the test
Measurement Description Measurement Unit Interpretation

Physical reads:

Indicates the rate at which the queries directly executed on and read from the physical disk.

Reads/Sec

A high value could indicate that direct disk accesses are occurring too frequently. This in turn implies poor cache usage. You may consider resizing your cache to accommodate more number of queries, so that direct disk reads are reduced.  

Avg physical reads:

Indicates the average number of reads performed by the queries that executed directly on the physical disk.

Number

A high value indicates that one/more queries are reading too frequently from the physical disk. This is an unhealthy practice and can be attributed poor cache usage.

Use the detailed diagnosis of this measure to know which queries are not executing in the cache and the number of times each of these queries read directly from the physical disk. This way, you can quickly identify that query which exerts the maximum pressure on the physical disk.

Logical reads:

Indicates the rate of data reads performed by queries to the cache.

Reads/Sec

A high value is desired for this measure. A low value is indicative of ineffective cache usage, typically caused by improper cache size.

Avg logical reads:

Indicates the average number of data reads performed by queries to the cache.

Number

A high value is desired for this measure. A low value is indicative of ineffective cache usage, typically caused by improper cache size.

You can also use the detailed diagnosis of this measure to view the top-5 queries in terms of number of logical reads. This way, you can precisely identify the most I/O-intensive query to the cache.

Logical writes:

Indicates the rate at which the cached queries performed writes.

Writes/Sec

A high value is desired for this measure. A low value is indicative of ineffective cache usage, typically caused by improper cache size.

Avg logical writes:

Indicates the average number of times data writes were performed by a query to the cache.

Number

A high value is desired for this measure. A low value is indicative of ineffective cache usage, typically caused by improper cache size.

You can also use the detailed diagnosis of this measure to view the top-5 queries in terms of number of logical writes. This way, you can precisely identify the most I/O-intensive query to the cache. 

CPU time:

Indicates the percentage of time for which the cached queries hogged the CPU.

Percent

A high value is indicative of excessive CPU usage by the cached queries. Use the detailed diagnosis of this measure to know which query is CPU-intensive.

Max elapsed time:

Indicates the maximum time taken by the cached queries for execution.

Secs

If the value of this measure is very high, it could either indicate that the database is unable to process the queries quickly or that one/more queries to the database are taking too long to execute. Improper indexing and fragmented tables in the database are common causes for slowdowns at the database-level. Besides the above, queries that are improperly structured can also take time to execute. The longer a query executes on the database, higher would be the resource consumption of that query. It is therefore imperative that such resource-intensive queries are quickly isolated and fine-tuned, so as to prevent degradations in the performance of the database server. Using the detailed diagnosis of this measure, you can rapidly identify the resource-intensive queries to the database.

Recently executed queries:

Indicates the number of queries that executed in the cache since the last measurement period.

Number

A consistent rise in the value of this measure is a sign of optimal cache usage and minimal direct disk accesses.

The detailed diagnosis of the Avg physical read measure lists the top-5 queries in terms of the number of times they read directly from the physical disk. The query that exerts the maximum pressure on the disk can thus be isolated.

DDavgphysicalreads

Figure 1 : The detailed diagnosis of the Avg physical reads measure

DDavgphysicalreads(a)

Figure 2 : The detailed diagnosis of the Avg physical reads measure

The detailed diagnosis of the Avg logical reads measure lists the top-5 cached queries in terms of the number of logical reads. The cached query that performed the maximum number of data reads can be identified. You can even analyse the query to figure out whether the number of reads it generates is justified or not; if not, you may have to optimize the query.

DDavglogicalreads

Figure 3 : The detailed diagnosis of the Avg logical reads measure

The detailed diagnosis of the Avg logical writes measure lists the top-5 cached queries in terms of the number of logical writes. The cached query that performed the maximum number of data writes can be inferred from this. You can even analyze the query to figure out whether the number of writes it generates is justified or not; if not, you may have to optimize the query.

DDavglogicalreads

Figure 4 : The detailed diagnosis of the Avg logical reads measure

The detailed diagnosis of the Max elapsed time measure lists the top-5 cached queries in terms of the time they took to complete execution. The query that took the longest time to execute can thus be easily identified. You can analyse whey that query took long to execute, assess the resource foot print of that query, and if required, attempt to fine-tune the query to reduce execution time / resource usage.

maxelapsedtime

Figure 5 : The detailed diagnosis of the Max elapsed time measure

The detailed diagnosis of the Cpu time measure lists the top-5 cached queries in terms of CPU usage. The most CPU-intensive  query can thus be identified and the reasons for the same can be determined.

DDmaxCPUtime

Figure 6 : The detailed diagnosis of the Cpu time measure