Overview
SQL Query Stress collects detailed performance statistics during load tests by leveraging SQL Server’s built-in statistics features (SET STATISTICS IO and SET STATISTICS TIME). This page documents all collected metrics, how they are gathered, and how to interpret them.
Collected Metrics
All metrics are stored in theQueryOutput class (defined in LoadEngine.cs:535-560) and collected per query execution.
Core Metrics
Description: Total elapsed time for the query execution as measured by the client using
System.Diagnostics.Stopwatch.Unit: TimeSpan (milliseconds precision)Interpretation: Includes network latency, data retrieval time, and all client-side processing. This is wall-clock time from when the query starts until it completes.Source: Client-side stopwatch measurementDescription: Total CPU time consumed by SQL Server executing the query.Unit: MillisecondsInterpretation: Actual CPU processing time on the server. Does not include wait time for I/O, locks, or other resources. A query with high
CpuTime relative to ElapsedTime is CPU-bound.Source: Parsed from SET STATISTICS TIME ON outputCollection: Enabled when CollectTimeStats is trueDescription: Total elapsed time as reported by SQL Server.Unit: MillisecondsInterpretation: Server-side measurement of query duration. Includes CPU time plus all wait time (I/O, locks, parallelism waits, etc.). Does not include network transmission time.Source: Parsed from
SET STATISTICS TIME ON outputCollection: Enabled when CollectTimeStats is trueDescription: Total number of logical reads (8KB pages) performed by the query across all tables.Unit: Pages (8KB each)Interpretation: Number of data pages read from the buffer cache (includes both cached and disk-read pages). Higher values indicate more data being scanned. Reducing logical reads through better indexing improves performance.Source: Summed from
SET STATISTICS IO ON output for all tablesCollection: Enabled when CollectIoStats is trueDescription: Indicates whether this was the last iteration for the thread.Interpretation: Used internally to track test progress and determine when threads complete.
Description: Number of threads still running at the time this result was recorded.Interpretation: Useful for understanding load characteristics over time. Shows how many concurrent connections were active.
Description: Exception object if the query execution failed.Interpretation: Contains detailed error information. Null if the query succeeded. Check for connection errors, timeout errors, or SQL syntax errors.
How Statistics Are Collected
1. Enabling Statistics Collection
WhenCollectIoStats or CollectTimeStats is enabled in the configuration, SQL Query Stress executes the following commands before running queries:
LoadEngine.cs:139-144
2. InfoMessage Event Handling
SQL Server sends statistics as informational messages through theSqlConnection.InfoMessage event. SQL Query Stress attaches an event handler (GetInfoMessages method at LoadEngine.cs:343-365) to capture these messages.
3. Regex Pattern Matching
Statistics are extracted from InfoMessage text using compiled regular expressions:Logical Reads Pattern
LoadEngine.cs:280
CPU and Elapsed Time Pattern
- First captured group: CPU time in milliseconds (156)
- Second captured group: Elapsed time in milliseconds (2034)
LoadEngine.cs:284-287
4. Accumulation
When multiple tables are accessed, logical reads are summed across all tables. CPU and elapsed time are accumulated across parse/compile and execution phases. Reference:LoadEngine.cs:347-363
Understanding Statistics IO Output
WhenSET STATISTICS IO ON is enabled, SQL Server provides detailed I/O information:
What SQL Query Stress Tracks
| Metric | Tracked | Description |
|---|---|---|
| Logical Reads | ✅ Yes | Pages read from buffer cache |
| Physical Reads | ❌ No | Pages read from disk |
| Read-ahead Reads | ❌ No | Pages read by read-ahead mechanism |
| Scan Count | ❌ No | Number of seeks/scans performed |
| LOB Reads | ❌ No | Large object read operations |
Understanding Statistics Time Output
WhenSET STATISTICS TIME ON is enabled, SQL Server provides timing information:
Metric Interpretation
| Metric | Description | High Value Indicates |
|---|---|---|
| CPU Time | Pure computation time | CPU-bound operations, calculations, aggregations |
| Elapsed Time | Total server-side time | I/O waits, lock waits, parallelism waits |
| Time (Client) | Client-measured time | Network latency, result set transfer |
Common Patterns
CPU-Bound Query:- CPU ≈ Elapsed Time
- Query spent most time in computation
- Optimize with better algorithms, indexing, or reduce data volume
- Elapsed Time >> CPU Time
- Query spent most time waiting for I/O
- Optimize with better indexing, caching, or faster storage
- Very low CPU, very high elapsed time
- Query spent most time waiting for locks
- Review isolation levels, add WITH (NOLOCK) if appropriate, or optimize locking strategy
Aggregated Statistics
During a load test, the UI displays aggregated statistics across all query executions:Calculated Metrics
Total Queries Executed:Configuration Impact on Statistics
ForceDataRetrieval Setting
Whenfalse (default):
- Executes query with
ExecuteNonQuery() - Results are generated but not transmitted to client
- Lower client-side
Timemeasurements - More representative of write operations
true:
- Reads all result sets completely using
ExecuteReader() - Forces full data retrieval and network transmission
- Higher client-side
Timemeasurements - More representative of read operations with data consumption
LoadEngine.cs:416-433
Statistics Collection Overhead
Enabling statistics collection adds minimal overhead:- CollectIoStats: ~1-5% overhead (parsing InfoMessages)
- CollectTimeStats: ~1-5% overhead (parsing InfoMessages)
Best Practices
For Performance Testing
-
Enable both statistics types to get complete picture:
-
Use ForceDataRetrieval when testing read workloads:
- Monitor logical reads to validate index effectiveness
- Compare CPU vs Elapsed Time to identify bottleneck type
For Accurate Measurements
- Run warm-up iterations before collecting final statistics
- Use sufficient iterations to get statistically significant averages
- Monitor
ActiveThreadsto ensure consistent concurrency - Check for exceptions (
Efield) that might skew results
Related
- Configuration File Format - Enable statistics collection settings
- CLI Command Reference - Run tests from command line
- Interpreting Results - Interpret test results in the UI