27-压力测试

测试目标 & 测试数据

● 测试目标

○ 测试集群的读写性能 / 做集群容量规划

○ 对 ES 配置参数进行修改,评估优化效果

○ 修改 Mapping 和 Setting,对数据建模进行优化,并测试评估性能改进

○ 测试 ES 新版本,结合实际场景和老版本进行比较,评估是否进行升级

● 测试数据

○ 数据量 / 数据分布

测试脚本

● ES 本身提供了 REST API,所以,可以通过很多传统的性能测试工具

○ Load Runner (商业软件,支持录制+重放 + DSL )

○ JMeter ( Apache 开源 ,Record & Play)

○ Gatling (开源,支持写 Scala 代码 + DSL)

● 专门为 Elasticsearch 设计的工具

○ ES Pref & Elasticsearch-stress-test

○ Elastic Rally

ES Rally 简介

● Elastic 官方开源,基于 Python 3 的压力测试工具

https://github.com/elastic/rally

○ 性能测试结果比较: https://elasticsearch-benchmarks.elastic.co

● 功能介绍

○ 自动创建,配置,运行测试,并且销毁 ES 集群

○ 支持不同的测试数据的比较,也支持将数据导入 ES 集群,进行二次分析

○ 支持测试时指标数据的搜集,方便对测试结果进行深度的分析

Rally 的安装以及入门

● 安装运行

○ Python 3.4+ 和 pip3 / JDK 8 / git 1.9+

○ 运行 pip3 install esrally

○ 运行 esrally configure

● 运行

○ 运行 esrally --distribution-version=7.1.0

○ 运行 1000 条测试数据: esrally --distribution-version=7.1.0 --test-mode

Rally 基本概念讲解

Tournament-- 定义测试目标,由多个 race 组成

○ Esrally list races

Track-- 赛道:测试数据和测试场景与策略

https://github.com/elastic/rallytracks

○ esrally list tracks

Car-- 执行测试方案

○ 不同配置的 es 实例

Award-- 测试结果和报告

运行一个测试

https://esrally.readthedocs.io/en/stable/tournament.html

什么是压测的流程

● Pipeline 指的是压测的一个流程

○ Esrally list pipelines

● 默认的流程

○ From-source-complete

○ From-source-skip-build

○ From-distribution

○ Benchmark-only (对已有的集群进行测试)

自定义 & 分布式测试

● Car

https://esrally.readthedocs.io/en/latest/car.html

○ 使用自建的集群

● Track

○ 自带的测试数据集:Nyc_taxis 4.5 G / logging 1.2G

○ 更多的测试数据集: https://github.com/elastic/rally-tracks

● 分布式测试

https://esrally.readthedocs.io/en/latest/recipes.html#recipe-distributed-load-driver

实例:比较不同的版本的性能

● 测试

○ esrally race --distribution-version=6.0.0 --track=nyc_taxis --challenge=append-no-conflicts --user-tag="version:6.0.0"

○ esrally race --distribution-version=7.1.0 --track=nyc_taxis --challenge=append-no-conflicts --user-tag="version:7.1.0"

● 比较结果

○ esrally list races

○ esrally compare --baseline=[6.0.0 race] --contender=[7.1.0 race]

实例:比较不同 Mapping 的性能

● 测试

○ esrally race --distribution-version=7.1.0 --track=nyc_taxis --challenge=append-no-conflicts --user-tag="enableSource:true" --include-tasks="type:index"

○ 修改:benchmarks/tracks/default/nyc_taxis/mappings.json,修改 _source.enabled 为 false

○ esrally race --distribution-version=7.1.0 --track=nyc_taxis --challenge=append-no-conflicts --user-tag="enableSource:false" --include-tasks="type:index

● 比较

○ esrally compare --baseline=[enableAll race] --contender=[disableAll race]

实例:测试现有集群的性能

● 测试

○ esrally race --pipeline=benchmark-only --target-hosts=127.0.0.1:9200 --track=geonames -- challenge=append-no-conflicts

相关推荐
Elastic 中国社区官方博客7 小时前
DevRel 通讯 — 2026 年 2 月
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·jina
Elastic 中国社区官方博客14 小时前
Elasticsearch:使用 Workflow 查询天气,发送消息到 Slack
大数据·运维·人工智能·elasticsearch·搜索引擎·ai
Elastic 中国社区官方博客20 小时前
AI 可观察性:公共部门使命韧性的支柱
大数据·人工智能·功能测试·elasticsearch·搜索引擎·语言模型·全文检索
Elastic 中国社区官方博客21 小时前
可执行操作的 AI agents:使用 Agent Builder 和 Workflows 自动化 IT 请求
大数据·数据库·人工智能·elasticsearch·搜索引擎·自动化·全文检索
玄〤1 天前
Elasticsearch 概念与基础实操 (索引、映射与文档操作)(黑马微服务课day12)
大数据·elasticsearch·微服务·全文检索
海兰1 天前
Elasticsearch Mapping 解析
大数据·elasticsearch·搜索引擎
海兰1 天前
Elasticsearch 自管理集群配置指南
大数据·elasticsearch·jenkins
海兰1 天前
Elasticsearch 全文检索概述
elasticsearch·serverless·全文检索
海兰1 天前
Elasticsearch 搜索方案与技术栈深度解析
大数据·elasticsearch·django