作者:来自 Elastic json
Elastic Cloud Serverless ( ECS ) 的 split-tier 架构设计将 indexing 任务与 search 分离。这意味着 indexing 和 search 可以根据系统的用户需求分别扩展。在后端,每个 tier 都有专用的 node pools,用于相应地管理计算资源需求。对于 indexing tier,当 indexing 负载(例如 indexing pressure、 CPU 和 memory 利用率、 write queue 饱和度)增加时,规模会以阶梯式扩展;当需求缓解时则会缩减。对于 search,tier 会根据摄入的数据量增长,并且可选地根据 search 负载扩展。
最棒的是,这个可扩展系统不需要最终用户进行管理。平台由 Elastic 完全托管。以下是一些在 Serverless 平台上优化 indexing 性能的建议。
- 新的 Serverless projects 从尽可能少的计算资源开始。这意味着只有在需要时才会消耗计算资源。
- 目标是将 bulk 延迟的中位数保持在 200 到 1000 毫秒之间。由于计划性的 object store flush,发送到 Serverless 的 bulk 请求最小响应时间为 200ms。这些 flush 是确保数据被正确持久化到 object storage 并可用于 search 的一部分。
- 为了获得高摄入性能,需要调优 bulk size 和 workers。可以从单个客户端的单个 bulk 请求响应时间开始测试,然后逐步增加。请确保在运行实验之前已加载所有 index templates。
- 如果 index 大小和规模是一个问题,请使用 data streams 而不是标准 indices。data streams 与标准 indices 的不同之处在于它们需要 @timestamp 字段,并由 data lifecycle policies 管理。在 serverless 中,data lifecycle 仅意味着分配数据保留期。data streams 最初是为高吞吐的 observability 和 security 工作负载设计的,具备超越标准 indices 的扩展能力,能够充分利用 Serverless 的扩展特性。
- 通过分散客户端工作负载来触发扩展。来自更多客户端的更多请求会促使你的 projects 扩展。从零开始扩展时,预计会以 429 的形式出现 backpressure。无论你是每天 1TB 还是 1PB 的用户,project 都需要逐步升温,并稳定到你的工作负载水平。
- 使用 Elasticsearch Rally 对摄入升温阶段和运行时的 indexing 吞吐量进行基准测试,可以使用你自己数据的样本,或者使用 Rally tracks repo 中的预定义工作负载。
我整理了一个脚本,用于实验不同的 bulk 请求大小和客户端数量。要使用它,请先安装 Astral uv,在脚本顶部设置标注的配置常量,然后运行: ./async_bulk.py。
脚本在完成后会输出一些统计信息:
Starting indexing with 24 processes... Documents per process: 4,166,666 Workers per process: 75 ================================================== Bulk Indexing Statistics (Multi-Process) ================================================== Number of processes: 24 Total documents indexed: 99,999,984 Total bulk requests: 200016 Elapsed time: 237.26 seconds Indexing rate: 421,480.34 docs/sec Max queue depth: 10,000 documents Min bulk response time: 204.97 ms Median bulk response time: 1285.85 ms Max bulk response time: 4273.16 ms ==================================================如果使用 data stream:
PUT /_index_template/advent_cal_ds_template { "index_patterns": ["advent-ds*"], "data_stream": {}, "template": { "mappings": { "properties": { "@timestamp": { "type": "date" } } } } } PUT /_data_stream/advent-ds那么就在脚本中将 index name 设为 advent-ds。尽情使用吧!