esrally(elasticsearch压测工具)介绍(一)

 

一、介绍

esrally是elastic search官方用于对ES集群集群进行压测的工具,可使用esrally构建不同版本集群、不同参数和数据进行压力测试,并且支持对结果进行比较。也支持对远程集群压测。
rally:(汽车,摩托车等)拉力赛,所以相关属于也与拉力赛相关。
  • track:赛道;指压测用到的样本数据和压测策略。
  • car: 赛车;指被压测不同类型的es实例(执行压测方案)。可通过:esrally list cars 查看
Available cars:

Name                     Type    Description
-----------------------  ------  --------------------------------------
16gheap                  car     Sets the Java heap to 16GB
1gheap                   car     Sets the Java heap to 1GB
24gheap                  car     Sets the Java heap to 24GB
2gheap                   car     Sets the Java heap to 2GB
4gheap                   car     Sets the Java heap to 4GB
8gheap                   car     Sets the Java heap to 8GB
defaults                 car     Sets the Java heap to 1GB
basic-license            mixin   Basic License
debug-non-safepoints     mixin   More accurate CPU profiles
ea                       mixin   Enables Java assertions
fp                       mixin   Preserves frame pointers
g1gc                     mixin   Enables the G1 garbage collector
parallelgc               mixin   Enables the Parallel garbage collector
trial-license            mixin   Trial License
unpooled                 mixin   Enables Netty's unpooled allocator
x-pack-ml                mixin   X-Pack Machine Learning
x-pack-monitoring-http   mixin   X-Pack Monitoring (HTTP exporter)
x-pack-monitoring-local  mixin   X-Pack Monitoring (local exporter)
x-pack-security          mixin   X-Pack Security
zgc                      mixin   Enables the ZGC garbage collector
  • pipline: 管道;可通过esrally list piplines 查看
Available pipelines:

Name                     Description
-----------------------  ---------------------------------------------------------------------------------------------
from-sources-complete    Builds and provisions Elasticsearch, runs a benchmark and reports results.
from-sources-skip-build  Provisions Elasticsearch (skips the build), runs a benchmark and reports results.
from-distribution        Downloads an Elasticsearch distribution, provisions it, runs a benchmark and reports results.
benchmark-only           Assumes an already running Elasticsearch instance, runs a benchmark and reports results
  • from-sources-complete :表示从源代码构建ES, --revision参数可以指定一个ES的修订版本,默认为最新版本。
  • rom-sources-skip-build :表示如果之前已经通过源码构建过一次相同版本的ES了,那么本次将不再进行构建,这样可以节省测试的时间
  • from-distribution:esrally将下载正式的ES发行版来进行测试, --distribution-version 参数可以指定ES版本,最低支持1.7.5
  • benchmark-only :将对已有的ES集群进行压测,--target-hosts参数可以指定ES集群地址
  • race:比赛记录;指每次压测记录,如果没有指定track,则默认使用geonames track进行测试
Recent races:

Race ID                               Race Timestamp    Track     Track Parameters    Challenge            Car       User Tags      Track Revision  Team Revision
------------------------------------  ----------------  --------  ------------------  -------------------  --------  -----------  ----------------  ---------------
5af141b9-c910-4021-b4fc-beb4c3fc16aa  20220614T072535Z  geonames                      append-no-conflicts  external
1415f9ca-1008-4307-8763-cdbc9640d304  20220614T072211Z  geonames                      append-no-conflicts  external                        6622623
5bfe97af-2c60-4a0f-a568-0e5f087f6b61  20220614T032008Z  geonames                      append-no-conflicts  external                        6622623
46ad39e9-0959-4813-804d-4f95407d886d  20220613T072708Z  geonames                      append-no-conflicts  external                        6622623
06324f7b-ab1c-4d81-b06b-45e537909374  20220613T070715Z  geonames                      append-no-conflicts  external                        6622623
  • 备注:可以根据不同race进行比较,例如:
esrally compare --baseline= 46ad39e9-0959-4813-804d-4f95407d886d --contender=06324f7b-ab1c-4d81-b06b-45e537909374

二、安装

  1. Python3环境:确保环境存在

  2. esrally安装:

    1. 安装虚拟环境:(后一个venv为虚拟环境文件夹)
python3 -m venv venv
  1. 安装esrally
source venv/bin/activate
(venv): pip install esrally
  1. 其他安装:

    1. 压测本地已经存在ES环境,即: --pipeline=benchmark-only --target-hosts=http://目标ES地址:目标端口,不需要安装java jdk环境
    2. 本地新建不同ES版本环境,即:piplines里其他三种pipline方式,安装java

三、配置

  1. 创建配置:

(venv): esrally configure
  • 备注:配置完成后,会覆盖写esrally配置文件 ~/.rally/rally.ini
  1. 压测数据于方案track介绍:

  • 所在目录(默认): ~/.rally/benchmarks/tracks/default/
  • esally自带的track:
(venv) [binger@test-node-21 .rally]$ ll  ~/.rally/benchmarks/tracks/default/
total 8
-rwxr-xr-x 1 yangshujun docker 2217 Jun 13 14:15 download.sh
drwxr-xr-x 2 yangshujun docker   91 Jun 14 11:20 eql
drwxr-xr-x 5 yangshujun docker  164 Jun 14 17:18 geonames
drwxr-xr-x 4 yangshujun docker  112 Jun 13 14:15 geopoint
drwxr-xr-x 5 yangshujun docker  126 Jun 13 14:15 geopointshape
drwxr-xr-x 5 yangshujun docker  126 Jun 14 11:20 geoshape
drwxr-xr-x 5 yangshujun docker  222 Jun 14 11:20 http_logs
drwxr-xr-x 4 yangshujun docker   95 Jun 14 11:20 metricbeat
drwxr-xr-x 4 yangshujun docker  180 Jun 13 14:15 nested
drwxr-xr-x 5 yangshujun docker  149 Jun 14 11:20 noaa
drwxr-xr-x 5 yangshujun docker  142 Jun 14 11:20 nyc_taxis
drwxr-xr-x 4 yangshujun docker  112 Jun 13 14:15 percolator
drwxr-xr-x 4 yangshujun docker  128 Jun 13 14:15 pmc
-rw-r--r-- 1 yangshujun docker 2896 Jun 13 14:15 README.md
drwxr-xr-x 4 yangshujun docker  144 Jun 13 14:15 so

         1. track组成(以default为例)

(venv) [binger@test-node-21 .rally]$ tree  ~/.rally/benchmarks/tracks/default/geonames/
/home/binger/.rally/benchmarks/tracks/default/geonames/
├── challenges
│   ├── default.json
├── files.txt
├── index.json
├── operations
│   └── default.json
├── README.md
├── terms.txt
├── track.json
└── track.py

         2. track.json定义压测方案相关

    • operations定义了压测操作细则,包含:索引数据、term查询,range查询,聚合查询...
    • challenges定义详细的压测方案

         3. 离线数据集下载:

在使用esrally进行比赛(压测)时,默认会根据赛道(track)配置 ~/.rally/benchmarks/tracks/default/geonames/track.json (如下)中“base-url”、“source-file”构建下载数据。下载数据较慢,可提前下载好,置于 ~/.rally/benchmarks/data/geonames 目录下。
或者:我们在elastic官网github上可以看到esrally的数据集相关描述 https://github.com/elastic/rally-tracks,通过rally-track/download.sh 中,下载
{% import "rally.helpers" as rally with context %}
{
  "version": 2,
  "description": "POIs from Geonames",
  "data-url": "http://benchmarks.elasticsearch.org.s3.amazonaws.com/corpora/geonames",
  "indices": [
    {
      "name": "geonames",
      "body": "index.json"
    }
  ],
  "corpora": [
    {
      "name": "geonames",
      "base-url": "https://rally-tracks.elastic.co/geonames",
      "documents": [
        {
          "source-file": "documents-2.json.bz2",
          "document-count": 11396503,
          "compressed-bytes": 265208777,
          "uncompressed-bytes": 3547613828
        }
      ]
    }
  ],
  "operations": [
    {{ rally.collect(parts="operations/*.json") }}
  ],
  "challenges": [
    {{ rally.collect(parts="challenges/*.json") }}
  ]
}

 

三、进行压测

  1. 压测命令:

esrally race --pipeline=benchmark-only --target-hosts=http://目标地址:目标端口 --track=geonames --challenge=append-no-conflicts --offline --include-tasks="type:bulk"
  • --pipline
  • --target-hosts: 目标集群地址
  • --track:赛道(默认geonames)
  • --challenge:track默认json配置中“challenges”包含:"append-no-conflicts"、"append-no-conflicts-index-only"、"append-fast-with-conflicts"和"significant-text"等,默认为:"append-no-conflicts"
  • --include-tasks:用户只运行 challenge 中的部分task
  • --cluster-health=yellow: 默认会检测集群状态,非green状态会直接退出,添加该参数可避免该状态
  • --test-model: 用测试数据运行,数据快
  • --client-options:指定一些客户端连接选项,比如用户名和密码。
  1. 总结报告:

    1. 通过日志查看每次输出的结果报告: ~/.rally/logs
    2. 通过json查看每次输出的结果报告:~/.rally/benchmarks/races
    3. 报告对比:
esrally compare --baseline= 46ad39e9-0959-4813-804d-4f95407d886d --contender=06324f7b-ab1c-4d81-b06b-45e537909374
  1. 参数介绍:Elasticsearch压测之Esrally压测标准 - 云+社区 - 腾讯云 (tencent.com)
 

四、进行压测

  1.  markupsafe 版本异常
    • 异常描述
Traceback (most recent call last):
  File "/usr/local/bin/jupyter-lab", line 5, in <module>
    from jupyterlab.labapp import main
  File "/usr/local/lib/python3.8/dist-packages/jupyterlab/labapp.py", line 13, in <module>
    from jupyter_server.serverapp import flags
  File "/usr/local/lib/python3.8/dist-packages/jupyter_server/serverapp.py", line 39, in <module>
    from jinja2 import Environment, FileSystemLoader
  File "/usr/lib/python3/dist-packages/jinja2/__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 15, in <module>
    from jinja2 import nodes
  File "/usr/lib/python3/dist-packages/jinja2/nodes.py", line 23, in <module>
    from jinja2.utils import Markup
  File "/usr/lib/python3/dist-packages/jinja2/utils.py", line 656, in <module>
    from markupsafe import Markup, escape, soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/usr/local/lib/python3.8/dist-packages/markupsafe/__init__.py)
    • 解决办法:pip install markupsafe==2.0.1

五、参考:

posted @ 2022-06-14 20:19  binger0712  阅读(1336)  评论(0编辑  收藏  举报