fastapi-performance-metrics

fastapi-performance-metrics is a cursor rule for Cursor from holtwood/awesome-cursorrules-zh. It costs 5 tokens per session (773 once invoked), scanned A, original, MIT.

Rules for measuring and improving FastAPI performance, including response time, request capacity, error rate, resource use, database queries, caching, and load testing.

In plain words
What is it for?
Use it to monitor APIs with tools such as Prometheus, Grafana, or APM services and to guide performance testing and optimisation.
Why use it?
It helps reveal slow endpoints, failing requests, overloaded resources, and database bottlenecks.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it to monitor APIs with tools such as Prometheus, Grafana, or APM services and to guide performance testing and optimisation.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/holtwood/awesome-cursorrules-zh/fastapi-performance-metrics
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/holtwood/awesome-cursorrules-zh

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for fastapi-performance-metrics

README.md
[![agentmods](https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/fastapi-performance-metrics/github.svg)](https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/fastapi-performance-metrics)
Your own site
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/fastapi-performance-metrics"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/fastapi-performance-metrics/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for fastapi-performance-metrics

Your own site · 80×15
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/fastapi-performance-metrics"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/fastapi-performance-metrics.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 5 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 773 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00005 $0.00773
Opus 5 $0.00003 $0.00387
Sonnet 5 $0.00001 $0.00155
Haiku 4.5 $0.00001 $0.00077

Measured 6d ago against content hash 1de19d3ba2aa, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

fastapi-performance-metrics scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/rules/backend/python/fastapi-api-example/fastapi-performance-metrics.mdc · 46 lines

What it actually says

FastAPI 性能指标

本规则集定义了在 FastAPI 应用程序中监控和优化性能的关键指标和方法,旨在确保应用程序的高效运行和良好的用户体验。

1. 关键性能指标 (KPIs)

  • 响应时间 (Latency): API 端点处理请求并返回响应所需的时间。通常关注平均响应时间、P95 和 P99 响应时间。
  • 吞吐量 (Throughput): 单位时间内 API 端点能够处理的请求数量(例如,每秒请求数 RPS)。
  • 错误率 (Error Rate): 返回错误响应(例如,HTTP 5xx 状态码)的请求所占的百分比。
  • 资源利用率: CPU 使用率、内存使用率、磁盘 I/O 和网络 I/O。
  • 并发连接数: 同时连接到服务器的客户端数量。

2. 监控工具与实践

  • 日志: 使用结构化日志记录请求和响应信息,包括响应时间、状态码等。
  • Prometheus/Grafana: 集成 Prometheus 用于收集指标,Grafana 用于可视化和构建仪表盘。
    • FastAPI 性能中间件: 可以使用 starlette-exporter 或自定义中间件来暴露 Prometheus 指标。
  • APM (Application Performance Monitoring): 使用 Sentry、New Relic、Datadog 等 APM 工具进行更全面的应用性能监控和追踪。
  • 压力测试: 使用 Locust、JMeter、k6 等工具进行压力测试,模拟高并发场景,发现性能瓶颈。

3. 性能优化策略

  • 异步操作: 充分利用 FastAPI 的异步特性(async/await),尤其是在进行 I/O 密集型操作(如数据库查询、外部 API 调用)时。
  • 数据库优化:
    • 索引: 确保数据库表有适当的索引。
    • 查询优化: 避免 N+1 查询问题,使用连接查询或批量查询。
    • 连接池: 使用数据库连接池来管理数据库连接。
  • 缓存:
    • 内存缓存: 使用 Redis 或 Memcached 缓存频繁访问的数据。
    • HTTP 缓存: 利用 HTTP 缓存头(Cache-Control, ETag, Last-Modified)减少重复请求。
  • 数据序列化优化: 优化 Pydantic 模型的序列化和反序列化性能。
  • Gunicorn/Uvicorn 配置:
    • 工作进程数: 根据 CPU 核心数配置 Gunicorn 的工作进程数(通常为 2 * CPU_CORES + 1)。
    • Worker 类型: 对于 I/O 密集型应用,可以考虑使用 uvloophttptools 优化 Uvicorn。
  • 代码优化:
    • 避免不必要的计算: 减少每个请求中的计算量。
    • 延迟加载: 延迟加载不立即需要的数据或资源。
  • 限流: 实施速率限制以保护 API 免受滥用和过载。
  • CDN: 对于静态文件,使用 CDN 加速内容分发。
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 46 lines · 5 tokens per session scan A 1de19d3ba2aa

Subscribe to this mod's changes

fastapi-performance-metrics is a cursor rule published in the GitHub repository holtwood/awesome-cursorrules-zh (233 stars, last pushed 1mo ago), licensed MIT. It adds 5 tokens to every session and 773 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.