Connection Pooling Strategy
SQL Query Stress automatically configures connection pooling based on your thread count to eliminate pool allocation overhead during testing.Pool Size Configuration
TheLoadEngine sets both MinPoolSize and MaxPoolSize equal to your thread count (LoadEngine.cs:46-48):
Enable Connection Pooling
Always keep connection pooling enabled (default:true in QueryStressSettings.cs:121) unless you specifically need to test connection overhead. Disabling pooling will dramatically slow down your tests and produce unrealistic results for most scenarios.
Thread and Iteration Tuning
Thread Count Recommendations
Guidelines:- Low concurrency testing: 1-10 threads for single-user or light load scenarios
- Moderate concurrency: 10-50 threads for typical application load
- High concurrency: 50-200+ threads for stress testing under peak load
- Maximum throughput: Gradually increase threads until performance plateaus
Iteration Count
Each thread executes the query for the specified number of iterations (QueryStressSettings.cs:72). The total query executions = threads × iterations. Testing strategies:- Quick validation: 10-50 iterations per thread
- Performance baseline: 100-1000 iterations per thread
- Endurance testing: 10,000+ iterations to identify memory leaks or degradation
Query Delay Configuration
TheDelayBetweenQueries setting (QueryStressSettings.cs:84) adds a pause between each query execution within a thread.
When to Use Query Delay
Use delay (> 0ms) when:- Simulating realistic user think time
- Testing sustained load over time rather than maximum throughput
- Preventing resource exhaustion on test systems
- Matching production usage patterns (e.g., reports run every 30 seconds)
- Testing maximum throughput capacity
- Stress testing to find breaking points
- Measuring query execution time in isolation
The delay is implemented using
Task.Delay() (LoadEngine.cs:491) and supports cancellation tokens for responsive test stopping.ForceDataRetrieval vs ExecuteNonQuery
This setting significantly impacts what gets measured and how the server processes your query.ForceDataRetrieval = false (Default)
UsesExecuteNonQuery() (LoadEngine.cs:432):
- Best for: INSERT, UPDATE, DELETE, stored procedures without result sets
- Measures: Query execution time only
- Performance: Minimal client overhead
ForceDataRetrieval = true
UsesExecuteReader() and retrieves the first column of every row (LoadEngine.cs:418-428):
- Best for: SELECT queries, measuring complete data transfer time
- Measures: Query execution + network transfer + client processing
- Performance: Adds overhead for large result sets
CommandTimeout Configuration
TheCommandTimeout setting (QueryStressSettings.cs:30, default: 0 = infinite) controls how long SQL Server will execute a query before terminating it.
Timeout Guidelines
Recommended values:- Development/baseline: 30 seconds - catches obviously slow queries
- Production simulation: Match your application’s timeout (typically 30-120 seconds)
- Stress testing: 15-30 seconds - identifies queries that degrade under load
Timeout vs Connection Timeout
- ConnectionTimeout (QueryStressSettings.cs:36, default: 15s): Time allowed to establish connection
- CommandTimeout (QueryStressSettings.cs:30, default: 0): Time allowed for query execution
Statistics Collection Overhead
SQL Query Stress can collect IO and time statistics directly from SQL Server.CollectIoStats and CollectTimeStats
When enabled (both default totrue in QueryStressSettings.cs:122-123), the engine executes:
- Logical reads (LoadEngine.cs:280)
- CPU time (LoadEngine.cs:284-286)
- Elapsed time
Performance Impact
When to disable:- Pure throughput testing where you only care about queries/second
- Very high-volume tests (100,000+ iterations) where parsing overhead becomes noticeable
- Queries with very fast execution times (<1ms) where overhead is proportionally higher
- Understanding why queries are slow (logical reads indicate IO patterns)
- Comparing optimization attempts (did logical reads decrease?)
- Identifying CPU vs IO-bound queries
Thread Priority
All worker threads run atThreadPriority.BelowNormal (LoadEngine.cs:152) to prevent SQL Query Stress from overwhelming the test client machine. This is generally optimal but can be modified in the source if you need different behavior.
Connection Pool Management
The LoadEngine callsSqlConnection.ClearPool() (LoadEngine.cs:115) before testing begins to ensure a clean starting state. After test cancellation, SqlConnection.ClearAllPools() (LoadEngine.cs:194) cleans up all connections.
Pool clearing ensures each test run starts fresh and connections from previous tests don’t affect results.
Performance Testing Workflow
- Establish baseline: Run test with current query/schema (enable statistics)
- Make one change: Modify query, add index, or adjust settings
- Re-run identical test: Same threads, iterations, and settings
- Compare metrics: Focus on average execution time, logical reads, and CPU time
- Iterate: Make additional changes based on results