数据库流量控制
Database Traffic Control

原始链接: https://planetscale.com/blog/introducing-database-traffic-control

PlanetScale 推出了 **Database Traffic Control™**,这是一套全新的管理系统,旨在保护 Postgres 数据库免受失控查询和流量突增的影响。 长期以来,Postgres 缺乏原生的拒绝过载机制,往往会导致性能下降或系统崩溃。Traffic Control 通过允许开发者为特定的查询子集设置实时资源预算(CPU、并发数和延迟)来解决这一问题。流量可以根据指纹、应用程序名称、数据库用户或自定义 SQL 标签进行细分。 该系统具备两种操作模式:“警告”(Warn)模式用于监控潜在影响,“强制”(Enforce)模式用于主动拦截违规查询。这为多种场景提供了关键的控制手段,包括快速事件响应、基于优先级的流量整形、隔离 AI 代理流量,以及在多租户环境中保护高级别服务。 Traffic Control 直接集成在 PlanetScale 控制面板中,并兼容其 API 和 CLI,使团队能够主动防御数据库风险。通过应用细粒度的限制,组织可以确保非关键任务不会占用核心服务的资源,从而有效防止与数据库相关的故障。Traffic Control 现已向所有 PlanetScale Postgres 数据库开放。

抱歉。
相关文章

原文

Postgres has a fundamental gap when it comes to managing query traffic. When an unexpected spike of bad queries, or runaway workload hits your database, Postgres has no good way to fight back. It accepts every query thrown at it until performance degrades or, in the worst case, the server goes down.

Today we're introducing Database Traffic Control™, a Postgres traffic management system built into PlanetScale that lets you enforce flexible budgets on your database traffic. With Traffic Control, you decide in real time how much of your database's resources any given workload is allowed to consume, and Postgres enforces those limits.

Traffic Control allows you to create budgets that target subsets of your query traffic. You specify which queries fall into the budget using rules that match on different dimensions, including:

  • Query pattern: a specific query fingerprint identified in Insights
  • Application name: the app that sent the query
  • Postgres user: the database user executing queries
  • Custom tags: any metadata you attach to your queries via SQL comments (feature name, priority level, region, customer tier, etc.)

After deciding what queries you want in your budget, you define the resource limits the budget is allowed to utilize. You can place caps on things like CPU %, CPU burst limits, backend process concurrency, and per-query timing.

Budgets can run in warn mode to observe what would be throttled, or enforce mode to actively block queries that exceed limits. You can also switch between modes at any time.

PlanetScale Insights tracks statistics for every query running against your database. When something goes wrong, you can find the problematic query in Insights, see detailed usage data, and set up a budget to restrict it in just a few clicks.

Traffic Control is powerful and flexible. It's helpful in a variety of scenarios both for preventing and reducing the impact of database-related incidents.

Incident response

A rogue query is spiking CPU and degrading performance for your entire application. Find it in Insights, budget its resource usage, and stabilize your database while your team investigates and ships a fix.

Priority-based traffic shaping

Tag your queries by priority (high, medium, low) and create budgets for each tier. Core features like authentication and critical user flows can have higher limits, while lower-priority background jobs are kept from starving them out.

Isolating human from AI agent traffic

As AI-powered features drive more and more queries to your database, Traffic Control lets you set guardrails so automated traffic can't overwhelm the queries powering your human user experience.

Prioritizing paid tiers in multi-tenant apps

If you run a multi-tenant application, you can use tags to identify traffic by customer or tier, then budget accordingly. Enterprise customers stay protected during load spikes caused by trial users.

Traffic Control is available today for all PlanetScale Postgres databases. To start using it:

  1. Navigate to your database in the PlanetScale dashboard
  2. Open Insights and go to the Traffic control tab
  3. Create your first budget by selecting the tags and limits you want to enforce (Note: a database restart may be required)
  4. Start in warn mode to observe the impact before switching to enforce

To get the most out of Traffic Control, add sqlcommenter tags to your application's queries. This gives you rich dimensions for categorizing traffic.

Traffic Control is also available via the PlanetScale API and CLI, so you can automate budget creation as part of your deployment pipelines.

We built a demo tool to let you try it out and see it in action. Just clone onramp, and run onramp create to auto generate a schema, Traffic Control budgets, and rules.

You can also learn more in the Traffic Control documentation, read the behind-the-scenes deep dive, or follow along with our detailed feature walkthrough:

Traffic Control gives your Postgres database something it has never had: the ability to defend itself. Set up your first budget today and stop worrying about the next query that tries to take your database down.

联系我们 contact @ memedata.com