Hacker News 中文摘要

RSS订阅

Postgres 能扩展吗? -- Does Postgres Scale?

文章摘要

文章通过基准测试评估Postgres在构建持久化工作流系统时的扩展性,发现单台Postgres服务器可支持每秒14.4万次写入或4.3万工作流处理,每日可处理120亿次写入或40亿工作流,性能超出预期,完全满足多数场景需求。所有测试代码已开源。

文章总结

基准测试:Postgres工作流执行性能表现 | DBOS

在构建基于Postgres的持久化工作流执行系统时,最常被问到的问题是:"Postgres能扩展吗?"虽然许多技术团队声称Postgres具备扩展能力,但鲜少展示其实际性能表现。本文通过基准测试,量化了单台Postgres服务器的扩展能力。

核心发现

  • 写入吞吐量:单台Postgres服务器可持续处理14.4万次/秒的写入(相当于每日120亿次)
  • 工作流处理:可执行4.3万次/秒的持久化工作流(每日40亿次)
  • 队列性能:基于Postgres的队列可处理1.21万次/秒的工作流,通过多队列分区可提升至3.06万次/秒

测试环境

  • AWS RDS db.m7i.24xlarge实例
  • 配置:96 vCPU/384GB内存/12万预置IOPS(io2存储卷)
  • 开源测试代码:dbos-postgres-benchmark

性能瓶颈分析

  1. 写入测试

    • 测试表结构:UUIDv7主键+TEXT字段+时间戳
    • 瓶颈定位:WAL(预写日志)刷盘速度成为关键限制因素。通过pg_stat_activity监测发现,多数进程在等待WAL锁释放。
  2. 工作流测试

    • 每个工作流需2次写入(启动+完成)
    • 性能差异源于工作流状态表的复杂性(31列/9索引 vs 测试表的3列/1索引)
  3. 队列测试

    • 每个工作流需4次写入(入队/出队/启动/完成)
    • 新瓶颈:工作流状态表的行锁竞争。采用多队列分区后,性能回升至直接执行模式的70%。

扩展建议

对于更高负载需求,可通过多Postgres服务器分片实现近乎无限的扩展能力。

延伸资源

(注:原文中的图片链接及技术术语如UUIDv7/WAL/SKIP LOCKED等均保留原表述)

评论总结

以下是评论内容的总结:

1. DBOS的优势与认可

  • 主要观点:DBOS在持久化工作流方面表现出色,比Temporal更简单易用,适合处理大规模工作流。
  • 关键引用
    • "DBOS is amazing when it comes to Durable Workflows... Temporal is like Kubernetes while DBOS is like docker compose."
    • "Postgres scales impressively well (4 billion workflows per day... enough for most applications)."

2. PostgreSQL的扩展性争议

  • 主要观点:PostgreSQL在垂直扩展上表现良好,但水平扩展和高可用性存在疑问。
  • 关键引用
    • "Yes, you can scale it quite well vertically. But how about horizontally?"
    • "It scales beyond the needs that most people have in most situations."

3. PostgreSQL的性能问题

  • 主要观点:实际使用中,PostgreSQL在索引和大表插入时性能下降明显,与MySQL相比表现不佳。
  • 关键引用
    • "At 100m rows the insertion performance is down to a fraction... Postgres will happily insert hundreds of millions rows at a steady pace if we remove all indices."
    • "The exact same table and indices on MySQL... maintains more or less linear insertion performance well beyond 500m rows."

4. 基准测试的质疑

  • 主要观点:文章中的基准测试数据存在误导,未考虑实际运维中的性能衰减和配置优化。
  • 关键引用
    • "After 120K writes/s p50 spikes from 10ms to 1s... Quoting 144K is equivalent to quoting the throughput of a highway at the moment traffic comes to a standstill."
    • "300 seconds test duration?? This is not operational... performance numbers will degrade over time."

5. 配置与优化的必要性

  • 主要观点:PostgreSQL的扩展性依赖于复杂的配置和优化,需要专业知识。
  • 关键引用
    • "Postgres can scale, just like any database can scale... there's a lot of lore and esoterica required to get it to scale."
    • "They can adjust their checkpoint settings to increase throughput further."

6. 其他观点

  • 主要观点:讨论数据库时,常有不切实际的问题和过度关注未来扩展的倾向。
  • 关键引用
    • "The constant problem is that 'big scale' always means 'larger than I've seen'... Neither is a practical concern for nearly anyone."
    • "when discussing DB it becomes so so interesting not because db itself but the people trying to ask some infeasible questions."

总结反映了对DBOS和PostgreSQL性能、扩展性及实际应用的多样化观点,既有认可也有批评。