sqlstresscmd command-line tool provides a cross-platform way to automate SQL query stress testing. It uses the same load engine as the GUI application but can run on Windows, Linux, and macOS.
Installation
Download the appropriate version for your platform from GitHub releases. The tool requires the .NET 8.0 runtime.Quick Start
Run a simple test with a configuration file:Command-Line Options
sqlstresscmd supports the following command-line arguments:
Path to a saved session settings file (
.json format). This file contains all configuration including connection info, query, threads, and iterations.Database server to connect to. Overrides the server specified in the settings file.
Number of concurrent threads to use. Overrides the thread count in the settings file.Default: 1
Path to a
.sql script file to execute. Overrides the query in the settings file.Automatically save results to the specified file. Supports text or CSV format based on file extension.
Extract the
sample.json configuration file template to the current directory.Configuration File Format
The settings file is a JSON document with the following structure. Usesqlstresscmd -x to extract a template.
Sample Configuration
sample.json
Configuration Properties
Load Settings
- NumThreads: Number of concurrent threads (default: 1)
- NumIterations: Number of times each thread executes the query (default: 1)
- DelayBetweenQueries: Milliseconds to wait between iterations (default: 0)
Query Settings
- MainQuery: The T-SQL query to execute
- CommandTimeout: Query timeout in seconds (0 = unlimited)
- ForceDataRetrieval: Force reading all result rows (default: false)
Connection Settings
- Server: SQL Server instance name
- Database: Database name
- IntegratedAuth: Use Windows Authentication (default: true)
- Login: SQL Server login (if not using Windows Auth)
- Password: SQL Server password (if not using Windows Auth)
- ConnectTimeout: Connection timeout in seconds (default: 15)
- EnablePooling: Enable connection pooling (default: true)
- MaxPoolSize: Maximum connections in pool (0 = default)
- ApplicationIntent: 0 = ReadWrite, 1 = ReadOnly
Statistics Collection
- CollectIoStats: Capture logical reads (default: true)
- CollectTimeStats: Capture CPU and elapsed time (default: true)
Advanced Settings
- KillQueriesOnCancel: Immediately cancel queries on Ctrl+C (default: true)
- ConnectionTimeout: Connection establishment timeout
Usage Examples
Extract Sample Configuration
Generate a template configuration file:sample.json in the current directory.
Run with Configuration File
Execute a test using saved settings:Override Server
Test against a different server than specified in config:Override Thread Count
Run with more threads than the saved configuration:Use External SQL File
Execute a query from a file instead of the config:stored-proc-test.sql file:
Save Results Automatically
Export results to CSV for analysis:Combine Multiple Overrides
Run against a different server with more threads and save results:Output Format
The CLI displays results in a formatted table:CSV Export Format
When using-r results.csv, the output includes:
Automation Examples
Continuous Integration
Run as part of a CI/CD pipeline:Progressive Load Testing
Test with increasing thread counts:Compare Before/After Optimization
Best Practices
Use Version Control for Configuration Files
Use Version Control for Configuration Files
Store your
.json configuration files in version control alongside your database schema. This creates a history of performance tests and makes it easy to rerun historical tests.Separate Configs for Different Scenarios
Separate Configs for Different Scenarios
Create different configuration files for different test scenarios:
smoke-test.json- Quick validation with low loadbaseline.json- Standard load for comparisonsstress-test.json- Maximum load to find limits
Use Environment Variables for Secrets
Use Environment Variables for Secrets
Don’t store passwords in configuration files. Use environment variables or secure secret management:
Save Results with Timestamps
Save Results with Timestamps
Include timestamps in result filenames:
Troubleshooting
Connection Failures
If connection fails:- Verify the server name and instance
- Check if SQL Server allows remote connections
- Verify firewall rules allow the connection
- Test with
sqlcmdor the GUI tool first
Authentication Issues
For Windows Authentication:- Set
"IntegratedAuth": true - Omit
LoginandPassword
- Set
"IntegratedAuth": false - Provide
LoginandPassword
Timeout Errors
If queries timeout:- Increase
CommandTimeoutin the config - Set to
0for unlimited timeout (use with caution) - Verify the query executes successfully in SSMS
Next Steps
Query Parameterization
Learn how to use parameters in CLI tests
Interpreting Results
Understand the metrics from your tests
Connection Settings
Configure connection settings and SSMS compatibility
Using the GUI
Use the Windows GUI for interactive testing