Skip to content

[性能] DuckDB 连接模式 (Arc<Mutex<Connection>>) 潜在性能瓶颈分析 #80

@evan-zhang11

Description

@evan-zhang11

观察到的模式

当前使用 Arc<Mutex<Connection>> 包装 DuckDB 连接:

pub struct AppState {
    db: Arc<Mutex<duckdb::Connection>>,
    // ...
}

潜在影响

  1. 串行查询执行 - 每个请求都需要 db.lock().await,导致所有数据库查询串行执行
  2. 并发瓶颈 - 在高并发场景下,数据库访问可能成为瓶颈
  3. 响应延迟 - 长时间运行的查询会阻塞其他请求

当前缓解措施

  • 使用 moka 缓存瓦片数据(减少数据库查询)
  • DuckDB 本身性能较好(列式存储,分析型数据库)

建议

短期 (P3)

  1. 文档记录 - 在架构文档中说明这个设计决策及其权衡
  2. 监控 - 添加数据库锁等待时间的 metrics
  3. 基准测试 - 测量当前架构的并发能力

中期 (P4)

  1. 连接池 - 研究 DuckDB 是否支持连接池或多个连接
  2. 读写分离 - 考虑读操作使用单独的连接/缓存

长期 (P5)

  1. 异步驱动 - 如果有异步 DuckDB 驱动可用,考虑迁移

问题

  • DuckDB 是否支持多连接并发读取?
  • 当前部署场景的预期并发量是多少?
  • 是否有性能测试数据?

优先级

P3 - 低优先级,仅在遇到实际性能问题时需要处理

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions