4. RML utilities
For
many years, Microsoft Product Support Services (PSS) used a collection
of private tools for assisting in the diagnosis and resolution of
customer support issues. Now known as the replay markup language (RML)
utilities, PSS released them to the general public in 2004.
Available as a free download from the Microsoft website, the RML utilities, comprising ReadTrace, Reporter, and OStress, are used both for diagnosing performance problems and constructing stress-test scenarios.
ReadTrace and Reporter
When we defined our Profiler trace earlier in figure 1,
we chose to save the results to a database table. Doing so allows the
results of the trace to be examined in a variety of ways once the trace
is closed. For example, we could run the following query against the
specified table to determine the top 10 expensive queries from a
disk-usage perspective:
-- Top 10 most expensive queries from a disk usage perspective
SELECT TOP 10 TextData, CPU, (Reads + Writes) as DiskTotal, Duration
FROM dbo.[Workload Analysis]
ORDER BY DiskTotal DESC
Queries such as the above are among the many possible ways in which the results can be analyzed. Further, we can use the saved results as input for the Database Engine Tuning
Advisor, which will analyze the trace contents and make various
recommendations.
One
of the limitations of using Profiler for workload analysis such as this
is that query executions that are the same with the exception of the
literal values are difficult to analyze together as a group. Take these
two queries, for example:
SELECT * FROM [authors] WHERE [lastName] = 'Smith'
SELECT * FROM "authors" WHERE "lastName" = 'Brown'
These are really different versions of the same query, so grouping them together for the purpose of obtaining the aggregate
cost of the query is beneficial; however, without a significant amount
of string-manipulation logic, this would be difficult to achieve.
ReadTrace performs such grouping analysis automatically.
Executed at the command line with a number of input parameters including a trace file name, ReadTrace
Creates a new database, by default named PerfAnalysis, in a specified SQL Server instance
Analyzes and aggregates information contained within the trace file and stores the results in the PerfAnalysis database
Produces .RML files, which can be used as input for the OStress utility, which we'll discuss shortly
Launches the Reporter utility, which graphically summarizes the results captured in the PerfAnalysis database
The
first step in using ReadTrace is capturing a trace file. In order for
ReadTrace to work and provide the most beneficial analysis, we need to
include a number of events and columns in the trace. The help file
that's supplied with the RML utilities documents all the required
events and columns.
Once the trace file has been captured, the ReadTrace utility can be executed against it, an example of which follows:
Readtrace -IG:\Trace\SalesTrace_1.trc -o"c:\temp\rml" -SBNE-SQL-PR-01\SALES
Once
processing is complete, the Reporter utility automatically opens and
displays the results of the analysis. The example report shown in figure 7
demonstrates one of the clear advantages of using the
ReadTrace/Reporter utilities over manual analysis of SQL Profiler
results stored in a table. Note the {STR} value in the Query Template
column at the very bottom of the report for Query 1. The ReadTrace
utility analyzes and aggregates different executions of the same
query/stored procedure as a group by stripping out literal values such
as stored procedure parameter values. In the example shown, {STR}
represents RML's understanding of this as a parameter value. Thus, the
total cost of all executions of this stored procedure will be
automatically calculated.
In addition to
viewing the results of ReadTrace analysis via the Reporter utility, you
can directly query the PerfAnalysis database for more advanced analysis.
Finally,
one of the major benefits of ReadTrace is the .RML files it creates
once processing is complete. The OStress utility can use these files
for both replay and stress-testing purposes.
OStress
Like
ReadTrace, OStress is a command-line utility. It's used to execute a
command or series of commands against a supplied instance and database.
Its input can be a single inline query, a query file, or an .RML file
produced by the ReadTrace utility. Consider the following example:
ostress -o"c:\temp\o" -SBNE-SQL-PR-01\SALES -dOrders -iStress.sql -n10 -r25
The end result of running the above command will be to spawn 10 threads (-n parameter), each of which will execute the contents of the Stress.sql file against the Orders database 25 times (-r
parameter), for a total of 250 executions. Further, this could
potentially run on multiple machines simultaneously, each of which is
stressing the same database. You can imagine the scale of stress that
could be achieved!
The -i parameter also accepts RML files as input, and the -Q parameter is used for a single inline query. If an RML file is used, -m replay
can be used to instruct OStress to use replay mode instead of stress
mode. In replay mode, events are replayed in the sequence in which they
were captured. In contrast, stress mode replays events as fast as
possible for maximum stress.
When
used for stress-testing purposes, Profiler's trace replay and the RML
utilities share a common attribute: they generate load at a database
level only. In order to obtain confidence in the ability of all levels
of an application's infrastructure to withstand the expected production
load, such utilities are insufficient. In addressing this deficiency,
developers frequently use application load-generation tools such as
LoadRunner and Visual Studio Team System: Test Load Agent.
|
In addition to load generation and debugging, SQL Server Profiler can also be used in diagnosing deadlocks.