Skip to content

[Subtask]: 减少parser的内存分配 #11663

Closed

Description

@ouyuanning

Parent Issue

#11651

Detail of Subtask

use fixed buffer in Parser for each session

Describe implementation you've considered

No response

Additional information

No response

Activity

  1. added this to the 1.1.0 milestone on Sep 6, 2023
  2. added
    priority/p0
    and removed
    priority/p0
    on Oct 16, 2023
  3. modified the milestones: 1.1.0, 1.2.0 on Nov 20, 2023
  4. changed the title [-][Subtask]: use fixed buffer in Parser for each session[/-] [+][Subtask]: 减少parser的内存分配[/+] on Dec 4, 2023
  5. jensenojs commented on Dec 4, 2023

    @jensenojs
    Contributor

    技术方案变了, 从session级别的buffer(基于mmap的arena) -> 基于sync.Pool的对象池(呃呃呃好像是全局的buffer.?)

    相关issue为 : https://github.com/matrixorigin/MO-Cloud/issues/384, 然后这里想讨论的不是两种方案的兼容性, 我还没看后者的实现, 但原来需要区分某个对象的内存是来自于go的还是来自于mmap的, 成员的生命周期需要区分得非常清楚. 使用sync.Pool的方案可能也需要搞清楚, 所以下面罗列一下在切换方案之前需要梳理清楚的问题

    paser阶段的主要内存分配都是parser-tree, 在plan阶段也会有parser-tree的重写, 对于一般的SQL, 它的parser-tree在doComQuery结束之后就不需要了, 因此对于它们来说parser-tree的生命周期是QUERY级别的, 但是下面有些情况是特例, 它们会让parser-tree的内容跨越QUERY级别, 并且某些cases下有更细枝末节的东西需要扣.

    • plan-cache : 如果cache住的是parser-tree, 显然在本QEURY结束后它的内容不能释放
    • prepare/set : 这两个SQL的本身的语义就是跨越QUERY的
      • 对于prepare有更微妙的讨论
        • prepare stmt1 from select * from t
        • prepare stmt1 from "select * from t"
    • 条件注释: 本质上也是prepare和set
      • /*!40103 SET TIME_ZONE='+00:00' */; (摘自bvt用例)

    之前对于prepare/set有点小麻烦的事情是在进入parser之前就需要知道传递进去的是Query级别的buf还是Session的buf

    如果sync.Pool是全局的话,呃我不知道, 生命周期的问题是不是就解决了, 它可能会以一个新的方式呈现, 因为对于parser/plan/compile-tree, 它们的每个成员都手动把它放进池子听上去不靠谱, 可能写个递归来释放比较好. 然后呃好像就还是会碰到我上面说的问题.

    此外还有某些场景下会遇到的深拷贝

    下面两个issue在动手之前思考修改范围里面有没有什么生命周期的特例可能也是有帮助的
    plan-tree : https://github.com/matrixorigin/MO-Cloud/issues/1808
    compile-tree : https://github.com/matrixorigin/MO-Cloud/issues/1814

  6. modified the milestones: 1.2.0, 1.3.0-Backlog on Apr 1, 2024
  7. modified the milestones: 1.3.0-Backlog, 1.3.0 on Jul 1, 2024
  8. ouyuanning commented on Jul 23, 2024

    @ouyuanning
    ContributorAuthor

    其他的不用处理了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions