1、DataFunConDataFunCon#20242024Velox Memory ManagementVelox Memory Management段蒙 腾讯 高级工程师孟晓烜 Meta 软件工程师自我介绍 腾讯大数据Native Engine团队负责人 培养了3位Velox贡献者 目前贡献了147个commit,国内领先 Top Velox贡献者,#10,国内#1 Apache Uniffle founder&PPMCContentsContents目录目录Velox介绍Velox内存管理Spilling未来规划VeloxVelox介绍介绍Velox是什么Meta开源的,C+开发的,高性能
2、查询引擎库:Vectorized execution engine Push-based pipeline model 通用API,扩展性强,可重用 最终的物理计划作为输入 专注单机上查询执行优化,adaptive No parser,no optimizerVelox的愿景Velox概览 Type Scalar,map,struct,array.Vector Arrow-compatible,columnar memory layout Flat,dictionary,constant Expression Eval Fully vectorized,adaptive,peeling,con
3、stant folding Operators Join,Aggregation,OrderBy Resource Management Memory,cache,spilling,threads Functions Scalar,aggregate functions I/O Connectors,filesystem,file format,serializerVelox执行https:/prestodb.io/blog/2024/06/24/diving-into-the-presto-native-c-query-engine-presto-2-0/VeloxVelox MemoryM
4、emory ManagementManagement设计原则Velox内存系统是为在固定的内存资源中,有效、安全的支持运行高度多样性查询工作负载而设计的:内存分配 优化小块内存管理 优化查询内存分配模式 内存共享 查询级别的细粒度的内存使用追踪 运行的查询之间的公平内存共享与仲裁 内存容量 总容量限制 查询和缓存之间动态内存共享内存管理器 内存池(Memory Pool),内存使用容量的追踪与分配 仲裁器(Memory Arbitrator),内存容量的仲裁与共享 分配器(Memory Allocator),物理内存分配和总容量控制内存池内存池类型:Root pool,内存容量控制 Aggre
5、gate Pool,内存用量聚合 Leaf Pool,内存使用申请。预留与回收申请的申请的sizesize实际分配的实际分配的sizesize 16 MB按照1MB的粒度向上取整=64 MB按照8MB的粒度向上取整预留(Memory Reservation)Quantized 在memory arbitrator容量限制之内回收(Memory Reclaim)连接arbitrator与查询 通过disk spilling回收内存内存仲裁器管理所有查询的可用内存容量,在查询之间仲裁内存容量,以实现公平内存共享 确保分配所有查询的内存容量都在内存仲裁器的容量限制之内 查询被创建时从仲裁器获得一个初
6、始容量 执行过程中,查询可以从仲裁器获取增长的容量 Local memory arbitration,从查询自身回收 Global memory arbitration,从其它查询回收仲裁过程某个查询的内存池发起仲裁请求,增长容量:1.请求pool进入arbitration state2.获取所有候选pools的,即所有root pools3.请求pool如果超过最大容量限制则回收入自己4.Local arbitration:按照空闲容量排序候选pools,回收未使用的容量5.Global arbitration: