Skip to content

性能问题:MemorySystem 每次操作都创建新的数据库连接 #10

@Zld1994

Description

@Zld1994

问题描述

agentManager/memory/memory_system.py 中,MemorySystem 类的每个方法都创建新的 SQLite 连接,这会导致性能问题。

受影响的代码

def store(self, entry: MemoryEntry) -> str:
    with sqlite3.connect(self.db_path) as conn:  # 每次都创建新连接
        # ...

def retrieve(self, entry_id: str) -> Optional[MemoryEntry]:
    with sqlite3.connect(self.db_path) as conn:  # 每次都创建新连接
        # ...

潜在问题

  1. 频繁创建/销毁数据库连接导致性能下降
  2. 在高并发场景下性能会显著下降
  3. 数据库连接池没有被利用

建议修复

  1. 使用连接池(例如:sqlite3 连接池或 SQLAlchemy)
  2. 实现连接缓存机制
  3. 添加性能测试用例
  4. 考虑使用异步数据库驱动

优先级

中 - 这是一个性能优化问题

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions