AGENT SKILL

sqlpysim SQL 负载测试

sqlpysim

sqlsim 的 Python 移植版(公开预览),基于微软原生 `mssql-python` 驱动。适用于——在 Python 环境中运行 SQL 查询、脚本和多线程工作负载;混合工作负载文件(`-workload`);实时进度流式输出(`-stream-json`);周期性查询统计快照(`-querystats-interval`);比较原生 ODBC(sqlsim)与 `mssql-python` 的驱动行为;生成用于自动化的 sqlpysim JSON。不适用于——仅 sqlsim 支持的重放模式;设置应用名称(`-app`,该参数由驱动保留);精确的跨工具 JSON 兼容性;或需要尽可能低客户端开销的性能比较(请改用 sqlsim)。

适用职业数据工程师
使用场景数据库管理
License 许可
MIT
最近更新
2026-10-21
Stars
★ 49
Forks
4

01 前言 Front Matter

name
sqlpysim
description
Public Preview Python-based port of sqlsim built on Microsoft's native `mssql-python` driver. USE FOR — running SQL queries, scripts, and multi-threaded workloads from Python environments; mixed workload files (`-workload`); live progress streaming (`-stream-json`); periodic query-statistic snapshots (`-querystats-interval`); comparing driver behavior between native ODBC (sqlsim) and `mssql-python`; producing sqlpysim JSON for automation. DO NOT USE FOR — sqlsim-only replay modes; setting an application name (`-app`, which the driver reserves); exact cross-tool JSON compatibility; or performance comparisons that require the lowest possible client overhead (use sqlsim instead).

03 SKILL.md 正文

sqlpysim — Python port of sqlsim

Authoritative references

Prefer the installed, version-matched copies in the workspace release overlay. They match the script you will run and work offline:

  • Consumer-facing agent instructions: sqlpysim/AGENTS.md
  • User manual: sqlpysim/sqlpysim.md
  • Examples: sqlpysim/examples/

If the overlay is not installed, for example when this skill comes from an Agent Plugin, use the public copies. They track the latest release, so confirm an option exists in sqlpysim.py -h before relying on it:

Driver reference: https://github.com/microsoft/mssql-python

Installation prerequisite and entry-point discovery

This plugin supplies agent guidance, not the sqlpysim runtime. Install a sqlpysim release in the workspace and install its Python requirements before running a workload.

Resolve the entry point in this order:

  1. Workspace release overlay: python .\sqlpysim\sqlpysim.py.
  2. An installed sqlpysim command on PATH.

If neither exists, stop and report the missing prerequisite. Do not assume the Agent Plugin installation directory contains sqlpysim.py.

Canonical workspace command:

python .\sqlpysim\sqlpysim.py <args>

Core query invocations follow sqlsim's command shape. Advanced flags, validation, and JSON fields differ; consult the release notes before translating commands or parsers between tools.

Driver constraints (do not violate)

  • Import: from mssql_python import connect
  • Reserved keywords — driver controls these; do not set them in the connection string: APP, Application Name
  • Token auth must use attrs_before[SQL_COPT_SS_ACCESS_TOKEN] with a UTF-16LE / SQLLEN-prefixed buffer. There is NO access_token= parameter.
    SQL_COPT_SS_ACCESS_TOKEN = 1256
    token_bytes  = token.encode("utf-16le")
    token_struct = struct.pack(f"<I{len(token_bytes)}s", len(token_bytes), token_bytes)
    conn = connect(conn_str, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: token_struct})
    

Canonical patterns

# Local SQL Server, Windows Auth
python .\sqlpysim\sqlpysim.py -S localhost -E -C -Q "SELECT 1"

# Azure SQL with token
$token = az account get-access-token --resource https://database.windows.net --query accessToken -o tsv
$token | python .\sqlpysim\sqlpysim.py -S myserver.database.windows.net -d mydb -T - -Q "SELECT 1"

# Multi-threaded workload (quiet)
python .\sqlpysim\sqlpysim.py -S localhost -E -C -Q "SELECT 1" -n 10 -r 100 -q

# JSON for automation
python .\sqlpysim\sqlpysim.py -S localhost -E -C -i .\workload.sql -n 4 -r 50 -json -o results.json

# Per-query server statistics using the sqlsim JSON contract
python .\sqlpysim\sqlpysim.py -S localhost -E -C -i .\workload.sql -n 4 -r 50 -querystats -json -q -o results.json

# Mixed workload groups from a sqlsim-format workload file
python .\sqlpysim\sqlpysim.py -S localhost -E -C -workload .\workload.json -q

# Live progress for a supervising process: one JSON event per line on stdout
python .\sqlpysim\sqlpysim.py -S localhost -E -C -Q "SELECT 1" -n 4 -r 500 -stream-json -q

# Live progress plus canonical final JSON
python .\sqlpysim\sqlpysim.py -S localhost -E -C -Q "SELECT 1" -n 4 -r 500 `
  -stream-json -json -o final-results.json -q

# Periodic server-statistic snapshots while the run is in flight
python .\sqlpysim\sqlpysim.py -S localhost -E -C -Q "SELECT 1" -n 4 -r 500 -querystats-interval 5 -querystats-file live.json -q

# Secure password input for local applications and automation
$password | python .\sqlpysim\sqlpysim.py -S localhost -U testuser -P - -Q "SELECT 1"

Installation prerequisite

python -m pip install -r .\sqlpysim\requirements.txt

Rules

  1. Verify any driver syntax against the official mssql-python docs before writing or modifying connection code. Do not invent parameters.
  2. Never append 2>&1 or pipe through Select-String. Capture output into a PowerShell variable if needed.
  3. Parse sqlpysim JSON with ConvertFrom-Json, but do not assume its schema is identical to sqlsim.
  4. When comparing tools, limit assertions to documented shared behavior and account for driver-specific timing and metrics.
  5. For applications and automation, use -T - or -P - with redirected stdin so secrets do not appear in process arguments.
  6. -querystats reports sqlsim-compatible aggregates without querying DMVs or emitting query/plan hashes.
  7. -stream-json turns on JSON mode. Combine it with -json -o <file> to keep NDJSON on stdout and write the canonical final result to the file; combined mode requires -o. Events are cumulative and throughput_per_second is a running average, so compute deltas between events for a current rate.
  8. -querystats-interval implies -querystats and defaults its file to querystats-live.json. A write failure never fails the run and is reported once on the normal error channel, which is silent in -json and -stream-json modes; verify the file exists rather than relying on a message or the exit code.
  9. -app is rejected: mssql-python reserves the application name and always reports MSSQL-Python. Use sqlsim when the application name matters.
  10. Start load tests with a small -n value and scale gradually while monitoring client and server CPU, memory, network, and connection usage. High thread counts can exhaust client resources and invalidate results; use a dedicated client for significant load tests.

04 同仓库更多 Skills

microsoft
microsoft/sqlsimtools

sqlsim SQL 压测

sqlsim

使用 sqlsim CLI 对 SQL Server、Azure SQL Database、Azure SQL 托管实例或 Microsoft Fabric 中的 SQL 数据库运行 SQL 查询、脚本或多线程工作负载。适用于 —— 执行临时 T-SQL 或从 `.sql` 文件执行;以 N 线程 × R 次迭代进行压力/负载测试;测量连接/登录/取数耗时;生成用于自动化的 JSON 指标;捕获每条查询的统计信息(`-querystats`)。不适用于 —— 非 SQL Server 引擎(MySQL、Postgres、Oracle),或架构生成/数据加载(sqlsim 只运行查询,不生成架构)。

数据工程师数据库管理
★ 49
microsoft
microsoft/sqlsimtools

sqlsimtools 发布管理

sqlsimtools-release

构建、打包、验证并发布 sqlsimtools 发布资产。适用于:执行发布候选版本试运行、创建版本、打发布标签、发布 GitHub 草稿版本、校验归档内容、诊断失败的发布工作流,或修改任何发布脚本。不适用于:运行 sqlsim 或 sqlpysim 工作负载(请使用 sqlsim 或 sqlpysim 技能),或日常源代码编辑。

SRE 工程师部署与发布管理
★ 49
microsoft
microsoft/sqlsimtools

sqlsimtools 项目数据统计

sqlsimtools-project-stats

仅面向源码仓库维护者的报告,展示 sqlsimtools 项目当前数据:每个文件的版本下载次数、GitHub Pages 网站状态与点击量、14 天仓库浏览量、克隆数、来源引荐和热门页面,以及 Star 数、Fork 数和关注者数。适用场景:维护者询问项目统计、下载数量、某个版本被下载了多少次、网站或仓库流量、引荐来源,或使用情况相较此前数据的变化。不用于:工具运行遥测(sqlsimtools 不收集此类数据)、Google Search Console 或 Bing Webmaster Tools 数据(请在相应门户中查看),或运行 SQL 工作负载(请使用 sqlsim、sqlpysim 或 sqlsimstudio 技能)。

软件开发工程师开源项目增长与推广
★ 49
microsoft
microsoft/sqlsimtools

sqlsimtools 源码构建与测试

sqlsimtools-build

从源码构建和测试 sqlsimtools。适用场景:克隆仓库、搭建开发环境、编译 sqlsim、准备 sqlpysim、构建 sqlsim Studio、运行冒烟测试或完整测试套件、检查先决条件,或诊断 Windows 或 Linux 上的构建或测试失败。不用于:使用已发布工具运行 SQL 工作负载(请使用 sqlsim 或 sqlpysim 技能),或发布版本(请使用 sqlsimtools-release 技能)。

软件开发工程师开发环境与工具链管理
★ 49
microsoft
microsoft/sqlsimtools

sqlsim Studio 安装运行与监控

sqlsimstudio

当用户想要安装、启动、配置、认证、运行、监控、比较或排查已发布的 sqlsim Studio 时使用,包括 Windows 安装包、浏览器引导启动、sqlsim 或 sqlpysim 工作负载、JSON 结果、查询存储(Query Store)统计信息、取消操作、已保存的配置、主题或 A/B 比较。不用于:源码构建、CI、仓库手动验收测试或仓库负载测试分层录制。

软件开发工程师开发环境与工具链管理
★ 49
microsoft
microsoft/sqlsimtools

sqlsim Studio 手动验收测试

sqlsimstudio-manual-test

仅限源码仓库的、有指导的 sqlsim Studio 手动验收测试。当贡献者要求开始或继续仓库中的 MANUAL-TEST.md 检查清单、验证从当前 checkout 构建的候选发布版本、记录 GUI 证据、诊断验收失败,或生成会话报告时使用。不适用于:已安装/已发布 Studio 包的常规使用、Studio 工作负载执行、分级负载测试(请使用 sqlsimstudio-load-test),或常规 Studio 配置帮助(请使用 sqlsimstudio)。

测试工程师测试与质量保障
★ 49